mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
added proxy to all import operations using KeychainService
This commit is contained in:
parent
8be184d46f
commit
cc4ecb6be7
@ -45,7 +45,9 @@ import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
|||||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
||||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.NfcListenerFragment;
|
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.NfcListenerFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
|
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||||
|
|
||||||
|
|
||||||
public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListenerFragment {
|
public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListenerFragment {
|
||||||
@ -118,7 +120,19 @@ public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListe
|
|||||||
mNextButton.setOnClickListener(new View.OnClickListener() {
|
mNextButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -174,7 +188,7 @@ public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListe
|
|||||||
Preferences.getPreferences(getActivity()).getCloudSearchPrefs()), null);
|
Preferences.getPreferences(getActivity()).getCloudSearchPrefs()), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void importKey() {
|
public void importKey(ParcelableProxy parcelableProxy) {
|
||||||
|
|
||||||
// Message is received after decrypting is done in KeychainService
|
// Message is received after decrypting is done in KeychainService
|
||||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
|
||||||
@ -234,6 +248,8 @@ public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListe
|
|||||||
data.putString(KeychainService.IMPORT_KEY_SERVER, cloudPrefs.keyserver);
|
data.putString(KeychainService.IMPORT_KEY_SERVER, cloudPrefs.keyserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.putParcelable(KeychainService.EXTRA_PARCELABLE_PROXY, parcelableProxy);
|
||||||
|
|
||||||
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Create a new Messenger for the communication back
|
// Create a new Messenger for the communication back
|
||||||
|
@ -56,7 +56,9 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
|||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
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.Preferences;
|
||||||
|
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||||
|
|
||||||
public abstract class DecryptFragment
|
public abstract class DecryptFragment
|
||||||
extends CachingCryptoOperationFragment<PgpDecryptVerifyInputParcel, DecryptVerifyResult>
|
extends CachingCryptoOperationFragment<PgpDecryptVerifyInputParcel, DecryptVerifyResult>
|
||||||
@ -131,7 +133,7 @@ public abstract class DecryptFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lookupUnknownKey(long unknownKeyId) {
|
private void lookupUnknownKey(long unknownKeyId, ParcelableProxy parcelableProxy) {
|
||||||
|
|
||||||
// Message is received after importing is done in KeychainService
|
// Message is received after importing is done in KeychainService
|
||||||
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(getActivity()) {
|
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(getActivity()) {
|
||||||
@ -178,6 +180,8 @@ public abstract class DecryptFragment
|
|||||||
data.putParcelableArrayList(KeychainService.IMPORT_KEY_LIST, selectedEntries);
|
data.putParcelableArrayList(KeychainService.IMPORT_KEY_LIST, selectedEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.putParcelable(KeychainService.EXTRA_PARCELABLE_PROXY, parcelableProxy);
|
||||||
|
|
||||||
// Send all information needed to service to query keys in other thread
|
// Send all information needed to service to query keys in other thread
|
||||||
Intent intent = new Intent(getActivity(), KeychainService.class);
|
Intent intent = new Intent(getActivity(), KeychainService.class);
|
||||||
intent.setAction(KeychainService.ACTION_IMPORT_KEYRING);
|
intent.setAction(KeychainService.ACTION_IMPORT_KEYRING);
|
||||||
@ -434,7 +438,19 @@ public abstract class DecryptFragment
|
|||||||
mSignatureLayout.setOnClickListener(new View.OnClickListener() {
|
mSignatureLayout.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -47,7 +47,9 @@ import org.sufficientlysecure.keychain.service.KeychainService;
|
|||||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4;
|
import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -150,8 +152,7 @@ public class ImportKeysProxyActivity extends FragmentActivity {
|
|||||||
returnResult(intent);
|
returnResult(intent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final String fingerprint = uri.getEncodedSchemeSpecificPart().toLowerCase(Locale.ENGLISH);
|
||||||
String fingerprint = uri.getEncodedSchemeSpecificPart().toLowerCase(Locale.ENGLISH);
|
|
||||||
if (!fingerprint.matches("[a-fA-F0-9]{40}")) {
|
if (!fingerprint.matches("[a-fA-F0-9]{40}")) {
|
||||||
SingletonResult result = new SingletonResult(
|
SingletonResult result = new SingletonResult(
|
||||||
SingletonResult.RESULT_ERROR, LogType.MSG_WRONG_QR_CODE_FP);
|
SingletonResult.RESULT_ERROR, LogType.MSG_WRONG_QR_CODE_FP);
|
||||||
@ -167,7 +168,18 @@ public class ImportKeysProxyActivity extends FragmentActivity {
|
|||||||
setResult(RESULT_OK, result);
|
setResult(RESULT_OK, result);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
importKeys(fingerprint);
|
final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(this).getProxyPrefs();
|
||||||
|
Runnable ignoreTor = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
importKeys(fingerprint, new ParcelableProxy(null, -1, null));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs,
|
||||||
|
this)) {
|
||||||
|
importKeys(fingerprint, proxyPrefs.parcelableProxy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -187,23 +199,23 @@ public class ImportKeysProxyActivity extends FragmentActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void importKeys(byte[] keyringData) {
|
public void importKeys(byte[] keyringData, ParcelableProxy parcelableProxy) {
|
||||||
ParcelableKeyRing keyEntry = new ParcelableKeyRing(keyringData);
|
ParcelableKeyRing keyEntry = new ParcelableKeyRing(keyringData);
|
||||||
ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>();
|
ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>();
|
||||||
selectedEntries.add(keyEntry);
|
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);
|
ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null);
|
||||||
ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>();
|
ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>();
|
||||||
selectedEntries.add(keyEntry);
|
selectedEntries.add(keyEntry);
|
||||||
|
|
||||||
startImportService(selectedEntries);
|
startImportService(selectedEntries, parcelableProxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startImportService(ArrayList<ParcelableKeyRing> keyRings) {
|
private void startImportService(ArrayList<ParcelableKeyRing> keyRings, ParcelableProxy parcelableProxy) {
|
||||||
|
|
||||||
// Message is received after importing is done in KeychainService
|
// Message is received after importing is done in KeychainService
|
||||||
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(this) {
|
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(this) {
|
||||||
@ -258,6 +270,8 @@ public class ImportKeysProxyActivity extends FragmentActivity {
|
|||||||
|
|
||||||
data.putParcelableArrayList(KeychainService.IMPORT_KEY_LIST, keyRings);
|
data.putParcelableArrayList(KeychainService.IMPORT_KEY_LIST, keyRings);
|
||||||
|
|
||||||
|
data.putParcelable(KeychainService.EXTRA_PARCELABLE_PROXY, parcelableProxy);
|
||||||
|
|
||||||
// Send all information needed to service to query keys in other thread
|
// Send all information needed to service to query keys in other thread
|
||||||
Intent intent = new Intent(this, KeychainService.class);
|
Intent intent = new Intent(this, KeychainService.class);
|
||||||
intent.setAction(KeychainService.ACTION_IMPORT_KEYRING);
|
intent.setAction(KeychainService.ACTION_IMPORT_KEYRING);
|
||||||
@ -285,8 +299,19 @@ public class ImportKeysProxyActivity extends FragmentActivity {
|
|||||||
// only one message sent during the beam
|
// only one message sent during the beam
|
||||||
NdefMessage msg = (NdefMessage) rawMsgs[0];
|
NdefMessage msg = (NdefMessage) rawMsgs[0];
|
||||||
// record 0 contains the MIME type, record 1 is the AAR, if present
|
// record 0 contains the MIME type, record 1 is the AAR, if present
|
||||||
byte[] receivedKeyringBytes = msg.getRecords()[0].getPayload();
|
final byte[] receivedKeyringBytes = msg.getRecords()[0].getPayload();
|
||||||
importKeys(receivedKeyringBytes);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -71,15 +71,13 @@ import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
|||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.util.ExportHelper;
|
import org.sufficientlysecure.keychain.util.*;
|
||||||
import org.sufficientlysecure.keychain.util.FabContainer;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||||
import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
|
import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
|
||||||
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
|
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
|
||||||
|
|
||||||
@ -465,7 +463,19 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case R.id.menu_key_list_update_all_keys:
|
case R.id.menu_key_list_update_all_keys:
|
||||||
updateAllKeys();
|
final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity())
|
||||||
|
.getProxyPrefs();
|
||||||
|
Runnable ignoreTor = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
updateAllKeys(new ParcelableProxy(null, -1, null));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs,
|
||||||
|
getActivity())) {
|
||||||
|
updateAllKeys(proxyPrefs.parcelableProxy);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case R.id.menu_key_list_debug_cons:
|
case R.id.menu_key_list_debug_cons:
|
||||||
@ -552,7 +562,7 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
startActivityForResult(intent, REQUEST_ACTION);
|
startActivityForResult(intent, REQUEST_ACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAllKeys() {
|
private void updateAllKeys(ParcelableProxy parcelableProxy) {
|
||||||
Context context = getActivity();
|
Context context = getActivity();
|
||||||
|
|
||||||
ProviderHelper providerHelper = new ProviderHelper(context);
|
ProviderHelper providerHelper = new ProviderHelper(context);
|
||||||
@ -613,6 +623,8 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
|
|
||||||
data.putParcelableArrayList(KeychainService.IMPORT_KEY_LIST, keyList);
|
data.putParcelableArrayList(KeychainService.IMPORT_KEY_LIST, keyList);
|
||||||
|
|
||||||
|
data.putParcelable(KeychainService.EXTRA_PARCELABLE_PROXY, parcelableProxy);
|
||||||
|
|
||||||
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Create a new Messenger for the communication back
|
// Create a new Messenger for the communication back
|
||||||
|
@ -39,7 +39,9 @@ import org.sufficientlysecure.keychain.service.KeychainService;
|
|||||||
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the selected public key to a keyserver
|
* Sends the selected public key to a keyserver
|
||||||
@ -72,7 +74,19 @@ public class UploadKeyActivity extends BaseActivity {
|
|||||||
mUploadButton.setOnClickListener(new OnClickListener() {
|
mUploadButton.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -89,7 +103,7 @@ public class UploadKeyActivity extends BaseActivity {
|
|||||||
setContentView(R.layout.upload_key_activity);
|
setContentView(R.layout.upload_key_activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uploadKey() {
|
private void uploadKey(ParcelableProxy parcelableProxy) {
|
||||||
// Send all information needed to service to upload key in other thread
|
// Send all information needed to service to upload key in other thread
|
||||||
Intent intent = new Intent(this, KeychainService.class);
|
Intent intent = new Intent(this, KeychainService.class);
|
||||||
|
|
||||||
@ -106,6 +120,7 @@ public class UploadKeyActivity extends BaseActivity {
|
|||||||
data.putString(KeychainService.UPLOAD_KEY_SERVER, server);
|
data.putString(KeychainService.UPLOAD_KEY_SERVER, server);
|
||||||
|
|
||||||
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
||||||
|
intent.putExtra(KeychainService.EXTRA_PARCELABLE_PROXY, parcelableProxy);
|
||||||
|
|
||||||
// Message is received after uploading is done in KeychainService
|
// Message is received after uploading is done in KeychainService
|
||||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(this) {
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(this) {
|
||||||
|
@ -53,6 +53,7 @@ import android.widget.RelativeLayout;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import com.getbase.floatingactionbutton.FloatingActionButton;
|
import com.getbase.floatingactionbutton.FloatingActionButton;
|
||||||
|
import edu.cmu.cylab.starslinger.exchange.ExchangeActivity;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||||
@ -78,11 +79,8 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
|
|||||||
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
|
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||||
import org.sufficientlysecure.keychain.ui.util.QrCodeUtils;
|
import org.sufficientlysecure.keychain.ui.util.QrCodeUtils;
|
||||||
import org.sufficientlysecure.keychain.util.ContactHelper;
|
import org.sufficientlysecure.keychain.util.*;
|
||||||
import org.sufficientlysecure.keychain.util.ExportHelper;
|
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
|
||||||
import org.sufficientlysecure.keychain.util.NfcHelper;
|
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -352,7 +350,22 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
|||||||
}
|
}
|
||||||
case R.id.menu_key_view_refresh: {
|
case R.id.menu_key_view_refresh: {
|
||||||
try {
|
try {
|
||||||
updateFromKeyserver(mDataUri, mProviderHelper);
|
final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(this).getProxyPrefs();
|
||||||
|
Runnable ignoreTor = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
updateFromKeyserver(mDataUri, mProviderHelper, new ParcelableProxy(null, -1, null));
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Notify.create(ViewKeyActivity.this, R.string.error_key_not_found, Notify.Style.ERROR)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, this)) {
|
||||||
|
updateFromKeyserver(mDataUri, mProviderHelper, proxyPrefs.parcelableProxy);
|
||||||
|
}
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
Notify.create(this, R.string.error_key_not_found, Notify.Style.ERROR).show();
|
Notify.create(this, R.string.error_key_not_found, Notify.Style.ERROR).show();
|
||||||
}
|
}
|
||||||
@ -635,7 +648,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFromKeyserver(Uri dataUri, ProviderHelper providerHelper)
|
private void updateFromKeyserver(Uri dataUri, ProviderHelper providerHelper, ParcelableProxy parcelableProxy)
|
||||||
throws ProviderHelper.NotFoundException {
|
throws ProviderHelper.NotFoundException {
|
||||||
|
|
||||||
mIsRefreshing = true;
|
mIsRefreshing = true;
|
||||||
@ -689,6 +702,8 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
|||||||
|
|
||||||
data.putParcelableArrayList(KeychainService.IMPORT_KEY_LIST, entries);
|
data.putParcelableArrayList(KeychainService.IMPORT_KEY_LIST, entries);
|
||||||
|
|
||||||
|
data.putParcelable(KeychainService.EXTRA_PARCELABLE_PROXY, parcelableProxy);
|
||||||
|
|
||||||
// Send all information needed to service to query keys in other thread
|
// Send all information needed to service to query keys in other thread
|
||||||
Intent intent = new Intent(this, KeychainService.class);
|
Intent intent = new Intent(this, KeychainService.class);
|
||||||
intent.setAction(KeychainService.ACTION_IMPORT_KEYRING);
|
intent.setAction(KeychainService.ACTION_IMPORT_KEYRING);
|
||||||
|
@ -37,15 +37,16 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class EmailKeyHelper {
|
public class EmailKeyHelper {
|
||||||
|
|
||||||
public static void importContacts(Context context, Messenger messenger, Proxy proxy) {
|
public static void importContacts(Context context, Messenger messenger, ParcelableProxy parcelableProxy) {
|
||||||
importAll(context, messenger, ContactHelper.getContactMails(context), proxy);
|
importAll(context, messenger, ContactHelper.getContactMails(context), parcelableProxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void importAll(Context context, Messenger messenger, List<String> mails, Proxy proxy) {
|
public static void importAll(Context context, Messenger messenger, List<String> mails,
|
||||||
|
ParcelableProxy parcelableProxy) {
|
||||||
// Collect all candidates as ImportKeysListEntry (set for deduplication)
|
// Collect all candidates as ImportKeysListEntry (set for deduplication)
|
||||||
Set<ImportKeysListEntry> entries = new HashSet<>();
|
Set<ImportKeysListEntry> entries = new HashSet<>();
|
||||||
for (String mail : mails) {
|
for (String mail : mails) {
|
||||||
entries.addAll(getEmailKeys(context, mail, proxy));
|
entries.addAll(getEmailKeys(context, mail, parcelableProxy.getProxy()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put them in a list and import
|
// Put them in a list and import
|
||||||
@ -53,7 +54,7 @@ public class EmailKeyHelper {
|
|||||||
for (ImportKeysListEntry entry : entries) {
|
for (ImportKeysListEntry entry : entries) {
|
||||||
keys.add(new ParcelableKeyRing(entry.getFingerprintHex(), entry.getKeyIdHex(), null));
|
keys.add(new ParcelableKeyRing(entry.getFingerprintHex(), entry.getKeyIdHex(), null));
|
||||||
}
|
}
|
||||||
importKeys(context, messenger, keys);
|
importKeys(context, messenger, keys, parcelableProxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<ImportKeysListEntry> getEmailKeys(Context context, String mail, Proxy proxy) {
|
public static Set<ImportKeysListEntry> getEmailKeys(Context context, String mail, Proxy proxy) {
|
||||||
@ -79,11 +80,13 @@ public class EmailKeyHelper {
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void importKeys(Context context, Messenger messenger, ArrayList<ParcelableKeyRing> keys) {
|
private static void importKeys(Context context, Messenger messenger, ArrayList<ParcelableKeyRing> keys,
|
||||||
|
ParcelableProxy parcelableProxy) {
|
||||||
Intent importIntent = new Intent(context, KeychainService.class);
|
Intent importIntent = new Intent(context, KeychainService.class);
|
||||||
importIntent.setAction(KeychainService.ACTION_IMPORT_KEYRING);
|
importIntent.setAction(KeychainService.ACTION_IMPORT_KEYRING);
|
||||||
Bundle importData = new Bundle();
|
Bundle importData = new Bundle();
|
||||||
importData.putParcelableArrayList(KeychainService.IMPORT_KEY_LIST, keys);
|
importData.putParcelableArrayList(KeychainService.IMPORT_KEY_LIST, keys);
|
||||||
|
importData.putParcelable(KeychainService.EXTRA_PARCELABLE_PROXY, parcelableProxy);
|
||||||
importIntent.putExtra(KeychainService.EXTRA_DATA, importData);
|
importIntent.putExtra(KeychainService.EXTRA_DATA, importData);
|
||||||
importIntent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
importIntent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
|
@ -55,12 +55,17 @@ import android.content.Context;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.support.v4.app.DialogFragment;
|
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.R;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.InstallDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.InstallDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.OrbotStartDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.OrbotStartDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.PreferenceInstallDialogFragment;
|
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/
|
* 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);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
return intent;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,6 +183,8 @@
|
|||||||
<string name="pref_proxy_type_value_socks">"proxySocks"</string>
|
<string name="pref_proxy_type_value_socks">"proxySocks"</string>
|
||||||
|
|
||||||
<!-- OrbotHelper strings -->
|
<!-- OrbotHelper strings -->
|
||||||
|
<string name="orbot_ignore_tor">"Don\'t use Tor"</string>
|
||||||
|
|
||||||
<!-- InstallDialogFragment strings -->
|
<!-- InstallDialogFragment strings -->
|
||||||
<string name="orbot_install_dialog_title">Install Orbot to use Tor?</string>
|
<string name="orbot_install_dialog_title">Install Orbot to use Tor?</string>
|
||||||
<string name="orbot_install_dialog_install">"Install"</string>
|
<string name="orbot_install_dialog_install">"Install"</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user