diff options
Diffstat (limited to 'OpenKeychain/src')
8 files changed, 122 insertions, 21 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java index 945d42a24..4d85255ca 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java @@ -41,7 +41,9 @@ import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; import org.sufficientlysecure.keychain.ui.CreateKeyActivity.NfcListenerFragment; import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; +import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; public class CreateYubiKeyImportFragment @@ -120,7 +122,19 @@ public class CreateYubiKeyImportFragment mNextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - importKey(); + + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()).getProxyPrefs(); + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + importKey(new ParcelableProxy(null, -1, null)); + } + }; + + if(OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + getActivity())) { + importKey(proxyPrefs.parcelableProxy); + } } }); } @@ -176,7 +190,7 @@ public class CreateYubiKeyImportFragment Preferences.getPreferences(getActivity()).getCloudSearchPrefs()), null); } - public void importKey() { + public void importKey(ParcelableProxy parcelableProxy) { ArrayList<ParcelableKeyRing> keyList = new ArrayList<>(); keyList.add(new ParcelableKeyRing(mNfcFingerprint, null, null)); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index 4eb8cd5e8..adb15111d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -58,7 +58,9 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify.Style; +import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; public abstract class DecryptFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> { @@ -136,7 +138,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager. } } - private void lookupUnknownKey(long unknownKeyId) { + private void lookupUnknownKey(long unknownKeyId, ParcelableProxy parcelableProxy) { final ArrayList<ParcelableKeyRing> keyList; final String keyserver; @@ -427,7 +429,19 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager. mSignatureLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - lookupUnknownKey(signatureKeyId); + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()) + .getProxyPrefs(); + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + lookupUnknownKey(signatureKeyId, new ParcelableProxy(null, -1, null)); + } + }; + + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + getActivity())) { + lookupUnknownKey(signatureKeyId, proxyPrefs.parcelableProxy); + } } }); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java index da713d0d8..1a03b8102 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java @@ -44,7 +44,9 @@ import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.util.ArrayList; import java.util.Locale; @@ -157,8 +159,7 @@ public class ImportKeysProxyActivity extends FragmentActivity returnResult(intent); return; } - - String fingerprint = uri.getEncodedSchemeSpecificPart().toLowerCase(Locale.ENGLISH); + final String fingerprint = uri.getEncodedSchemeSpecificPart().toLowerCase(Locale.ENGLISH); if (!fingerprint.matches("[a-fA-F0-9]{40}")) { SingletonResult result = new SingletonResult( SingletonResult.RESULT_ERROR, LogType.MSG_WRONG_QR_CODE_FP); @@ -194,23 +195,23 @@ public class ImportKeysProxyActivity extends FragmentActivity } } - public void importKeys(byte[] keyringData) { + public void importKeys(byte[] keyringData, ParcelableProxy parcelableProxy) { ParcelableKeyRing keyEntry = new ParcelableKeyRing(keyringData); ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>(); selectedEntries.add(keyEntry); - startImportService(selectedEntries); + startImportService(selectedEntries, parcelableProxy); } - public void importKeys(String fingerprint) { + public void importKeys(String fingerprint, ParcelableProxy parcelableProxy) { ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null); ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>(); selectedEntries.add(keyEntry); - startImportService(selectedEntries); + startImportService(selectedEntries, parcelableProxy); } - private void startImportService(ArrayList<ParcelableKeyRing> keyRings) { + private void startImportService(ArrayList<ParcelableKeyRing> keyRings, ParcelableProxy parcelableProxy) { // search config { @@ -273,8 +274,19 @@ public class ImportKeysProxyActivity extends FragmentActivity // only one message sent during the beam NdefMessage msg = (NdefMessage) rawMsgs[0]; // record 0 contains the MIME type, record 1 is the AAR, if present - byte[] receivedKeyringBytes = msg.getRecords()[0].getPayload(); - importKeys(receivedKeyringBytes); + final byte[] receivedKeyringBytes = msg.getRecords()[0].getPayload(); + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(this) + .getProxyPrefs(); + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + importKeys(receivedKeyringBytes, new ParcelableProxy(null, -1, null)); + } + }; + + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, this)) { + importKeys(receivedKeyringBytes, proxyPrefs.parcelableProxy); + } } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index e038cf948..76ae147a2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -71,16 +71,17 @@ import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter; import org.sufficientlysecure.keychain.ui.util.Notify; -import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.util.ExportHelper; import org.sufficientlysecure.keychain.util.FabContainer; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter; import se.emilsjolander.stickylistheaders.StickyListHeadersListView; @@ -562,7 +563,7 @@ public class KeyListFragment extends LoaderFragment startActivityForResult(intent, REQUEST_ACTION); } - private void updateAllKeys() { + private void updateAllKeys(ParcelableProxy parcelableProxy) { Activity activity = getActivity(); if (activity == null) { return; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java index 8b49f3b96..ee37b4b98 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java @@ -37,7 +37,9 @@ import org.sufficientlysecure.keychain.service.ExportKeyringParcel; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; /** * Sends the selected public key to a keyserver @@ -76,7 +78,19 @@ public class UploadKeyActivity extends BaseActivity mUploadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - uploadKey(); + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(UploadKeyActivity.this) + .getProxyPrefs(); + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + uploadKey(proxyPrefs.parcelableProxy); + } + }; + + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + UploadKeyActivity.this)) { + uploadKey(proxyPrefs.parcelableProxy); + } } }); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 27832b665..da00748e4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -53,6 +53,7 @@ import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.getbase.floatingactionbutton.FloatingActionButton; +import edu.cmu.cylab.starslinger.exchange.ExchangeActivity; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; @@ -80,11 +81,6 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener; import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.ui.util.QrCodeUtils; -import org.sufficientlysecure.keychain.util.ContactHelper; -import org.sufficientlysecure.keychain.util.ExportHelper; -import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.NfcHelper; -import org.sufficientlysecure.keychain.util.Preferences; import java.io.IOException; import java.util.ArrayList; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotHelper.java index fb016f9e6..5e0e393c5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotHelper.java @@ -55,12 +55,17 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; +import android.os.Handler; +import android.os.Message; import android.os.Messenger; import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.dialog.InstallDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.OrbotStartDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.PreferenceInstallDialogFragment; +import org.sufficientlysecure.keychain.util.Preferences; /** * This class is taken from the NetCipher library: https://github.com/guardianproject/NetCipher/ @@ -130,4 +135,47 @@ public class OrbotHelper { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return intent; } + + /** + * checks if Tor is enabled and if it is, that Orbot is installed and runnign. Generates appropriate dialogs. + * + * @param middleButton resourceId of string to display as the middle button of install and enable dialogs + * @param middleButtonRunnable runnable to be executed if the user clicks on the middle button + * @param proxyPrefs + * @param fragmentActivity + * @return true if Tor is not enabled or Tor is enabled and Orbot is installed and running, else false + */ + public static boolean isOrbotInRequiredState(int middleButton, final Runnable middleButtonRunnable, + Preferences.ProxyPrefs proxyPrefs, FragmentActivity fragmentActivity) { + Handler ignoreTorHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + // every message received by this handler will mean the middle button was pressed + middleButtonRunnable.run(); + } + }; + + if (!proxyPrefs.torEnabled) { + return true; + } + + if(!OrbotHelper.isOrbotInstalled(fragmentActivity)) { + + OrbotHelper.getInstallDialogFragmentWithThirdButton( + new Messenger(ignoreTorHandler), + R.string.orbot_install_dialog_ignore_tor + ).show(fragmentActivity.getSupportFragmentManager(), "OrbotHelperOrbotInstallDialog"); + + return false; + } else if(!OrbotHelper.isOrbotRunning()) { + + OrbotHelper.getOrbotStartDialogFragment(new Messenger(ignoreTorHandler), + R.string.orbot_install_dialog_ignore_tor) + .show(fragmentActivity.getSupportFragmentManager(), "OrbotHelperOrbotStartDialog"); + + return false; + } else { + return true; + } + } } diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index fc392d6f8..f6892c664 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -190,6 +190,8 @@ <string name="pref_proxy_type_value_socks">"proxySocks"</string> <!-- OrbotHelper strings --> + <string name="orbot_ignore_tor">"Don\'t use Tor"</string> + <!-- InstallDialogFragment strings --> <string name="orbot_install_dialog_title">Install Orbot to use Tor?</string> <string name="orbot_install_dialog_install">"Install"</string> |