aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-03-06 16:30:36 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2015-03-06 17:12:45 +0100
commit088282483f57cf03d9ee75578cd9d3bf6a74a4d9 (patch)
tree0c3b02d255738087e44f8c011f7a669e7b11cf46 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked
parenta3ac2738ea6140c6a181f9b685249ad2f766f904 (diff)
downloadopen-keychain-088282483f57cf03d9ee75578cd9d3bf6a74a4d9.tar.gz
open-keychain-088282483f57cf03d9ee75578cd9d3bf6a74a4d9.tar.bz2
open-keychain-088282483f57cf03d9ee75578cd9d3bf6a74a4d9.zip
extract linked id create final fragment superclass
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateFinalFragment.java249
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep2Fragment.java247
2 files changed, 275 insertions, 221 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateFinalFragment.java
new file mode 100644
index 000000000..b02d70b33
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateFinalFragment.java
@@ -0,0 +1,249 @@
+package org.sufficientlysecure.keychain.ui.linked;
+
+import android.app.Activity;
+import android.app.ProgressDialog;
+import android.content.Intent;
+import android.graphics.PorterDuff;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.os.Message;
+import android.os.Messenger;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.operations.results.LinkedVerifyResult;
+import org.sufficientlysecure.keychain.operations.results.OperationResult;
+import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
+import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
+import org.sufficientlysecure.keychain.pgp.linked.LinkedIdentity;
+import org.sufficientlysecure.keychain.service.KeychainIntentService;
+import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
+import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
+import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
+import org.sufficientlysecure.keychain.ui.util.Notify;
+
+public abstract class LinkedIdCreateFinalFragment extends Fragment {
+
+ public static final String ARG_NONCE = "nonce";
+ protected static final int REQUEST_CODE_PASSPHRASE = 0x00007008;
+
+ LinkedIdWizard mLinkedIdWizard;
+
+ private ImageView mVerifyImage;
+ private View mVerifyProgress;
+ private TextView mVerifyStatus;
+ private int mResourceNonce;
+
+ // This is a resource, set AFTER it has been verified
+ LinkedCookieResource mVerifiedResource = null;
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ mLinkedIdWizard = (LinkedIdWizard) getActivity();
+
+ mResourceNonce = getArguments().getInt(ARG_NONCE);
+ }
+
+ protected abstract View newView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ final View view = newView(inflater, container, savedInstanceState);
+
+ view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ startCertify();
+ }
+ });
+
+ view.findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mLinkedIdWizard.loadFragment(null, null, LinkedIdWizard.FRAG_ACTION_TO_LEFT);
+ }
+ });
+
+ mVerifyImage = (ImageView) view.findViewById(R.id.verify_image);
+ mVerifyProgress = view.findViewById(R.id.verify_progress);
+ mVerifyStatus = (TextView) view.findViewById(R.id.verify_status);
+
+ view.findViewById(R.id.button_verify).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ proofVerify();
+ }
+ });
+
+ setVerifyProgress(false, null);
+ mVerifyStatus.setText(R.string.linked_verify_pending);
+
+ return view;
+ }
+
+
+ abstract LinkedCookieResource getResource();
+
+ private void setVerifyProgress(boolean on, Boolean success) {
+ mVerifyProgress.setVisibility(on ? View.VISIBLE : View.GONE);
+ mVerifyImage.setVisibility(on ? View.GONE : View.VISIBLE);
+ if (success == null) {
+ mVerifyStatus.setText(R.string.linked_verifying);
+ mVerifyImage.setImageResource(R.drawable.status_signature_unverified_cutout_24dp);
+ mVerifyImage.setColorFilter(getResources().getColor(R.color.tertiary_text_light),
+ PorterDuff.Mode.SRC_IN);
+ } else if (success) {
+ mVerifyStatus.setText(R.string.linked_verify_success);
+ mVerifyImage.setImageResource(R.drawable.status_signature_verified_cutout_24dp);
+ mVerifyImage.setColorFilter(getResources().getColor(R.color.android_green_dark),
+ PorterDuff.Mode.SRC_IN);
+ } else {
+ mVerifyStatus.setText(R.string.linked_verify_error);
+ mVerifyImage.setImageResource(R.drawable.status_signature_unknown_cutout_24dp);
+ mVerifyImage.setColorFilter(getResources().getColor(R.color.android_red_dark),
+ PorterDuff.Mode.SRC_IN);
+ }
+ }
+
+ private void proofVerify() {
+ setVerifyProgress(true, null);
+
+ final LinkedCookieResource resource = getResource();
+
+ new AsyncTask<Void,Void,LinkedVerifyResult>() {
+
+ @Override
+ protected LinkedVerifyResult doInBackground(Void... params) {
+ return resource.verify(mLinkedIdWizard.mFingerprint, mResourceNonce);
+ }
+
+ @Override
+ protected void onPostExecute(LinkedVerifyResult result) {
+ super.onPostExecute(result);
+ if (result.success()) {
+ setVerifyProgress(false, true);
+ mVerifiedResource = resource;
+ } else {
+ setVerifyProgress(false, false);
+ // on error, show error message
+ result.createNotify(getActivity()).show();
+ }
+ }
+ }.execute();
+
+ }
+
+ private void startCertify() {
+
+ if (mVerifiedResource == null) {
+ Notify.showNotify(getActivity(), R.string.linked_need_verify, Notify.Style.ERROR);
+ return;
+ }
+
+ Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class);
+ intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, mLinkedIdWizard.mMasterKeyId);
+ startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
+
+ }
+
+ private void certifyLinkedIdentity (String passphrase) {
+ KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
+ getActivity(),
+ getString(R.string.progress_saving),
+ ProgressDialog.STYLE_HORIZONTAL,
+ true) {
+ public void handleMessage(Message message) {
+ // handle messages by standard KeychainIntentServiceHandler first
+ super.handleMessage(message);
+
+ if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
+
+ // get returned data bundle
+ Bundle returnData = message.getData();
+ if (returnData == null) {
+ return;
+ }
+ final OperationResult result =
+ returnData.getParcelable(OperationResult.EXTRA_RESULT);
+ if (result == null) {
+ return;
+ }
+
+ // if bad -> display here!
+ if (!result.success()) {
+ result.createNotify(getActivity()).show();
+ return;
+ }
+
+ result.createNotify(getActivity()).show();
+
+ // if good -> finish, return result to showkey and display there!
+ // Intent intent = new Intent();
+ // intent.putExtra(OperationResult.EXTRA_RESULT, result);
+ // getActivity().setResult(EditKeyActivity.RESULT_OK, intent);
+
+ // AffirmationCreateHttpsStep3Fragment frag =
+ // AffirmationCreateHttpsStep3Fragment.newInstance(
+ // mResourceUri, mResourceNonce, mResourceString);
+
+ // mAffirmationWizard.loadFragment(null, frag, AffirmationWizard.FRAG_ACTION_TO_RIGHT);
+
+ }
+ }
+ };
+
+ SaveKeyringParcel skp =
+ new SaveKeyringParcel(mLinkedIdWizard.mMasterKeyId, mLinkedIdWizard.mFingerprint);
+
+ WrappedUserAttribute ua =
+ LinkedIdentity.fromResource(mVerifiedResource, mResourceNonce).toUserAttribute();
+
+ skp.mAddUserAttribute.add(ua);
+
+ // Send all information needed to service to import key in other thread
+ Intent intent = new Intent(getActivity(), KeychainIntentService.class);
+ intent.setAction(KeychainIntentService.ACTION_EDIT_KEYRING);
+
+ // fill values for this action
+ Bundle data = new Bundle();
+ data.putString(KeychainIntentService.EDIT_KEYRING_PASSPHRASE, passphrase);
+ data.putParcelable(KeychainIntentService.EDIT_KEYRING_PARCEL, skp);
+ intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
+
+ // Create a new Messenger for the communication back
+ Messenger messenger = new Messenger(saveHandler);
+ intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
+
+ // show progress dialog
+ saveHandler.showProgressDialog(getActivity());
+
+ // start service with intent
+ getActivity().startService(intent);
+
+ }
+
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ switch (requestCode) {
+ case REQUEST_CODE_PASSPHRASE:
+ if (resultCode == Activity.RESULT_OK && data != null) {
+ String passphrase =
+ data.getStringExtra(PassphraseDialogActivity.MESSAGE_DATA_PASSPHRASE);
+ certifyLinkedIdentity(passphrase);
+ }
+ break;
+ default:
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+ }
+
+}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep2Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep2Fragment.java
index 6a0c1cac0..adae7eaf5 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep2Fragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep2Fragment.java
@@ -17,39 +17,20 @@
package org.sufficientlysecure.keychain.ui.linked;
-import android.app.Activity;
-import android.app.ProgressDialog;
import android.content.Intent;
-import android.graphics.PorterDuff;
import android.net.Uri;
-import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
-import android.os.Message;
-import android.os.Messenger;
-import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
-import android.widget.ImageView;
-import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
-import org.sufficientlysecure.keychain.operations.results.LinkedVerifyResult;
-import org.sufficientlysecure.keychain.operations.results.OperationResult;
-import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
-import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
-import org.sufficientlysecure.keychain.pgp.linked.LinkedIdentity;
-import org.sufficientlysecure.keychain.pgp.linked.RawLinkedIdentity;
import org.sufficientlysecure.keychain.pgp.linked.resources.GenericHttpsResource;
-import org.sufficientlysecure.keychain.service.KeychainIntentService;
-import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
-import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
-import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import org.sufficientlysecure.keychain.util.FileHelper;
@@ -60,71 +41,59 @@ import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
-public class LinkedIdCreateHttpsStep2Fragment extends Fragment {
+public class LinkedIdCreateHttpsStep2Fragment extends LinkedIdCreateFinalFragment {
private static final int REQUEST_CODE_OUTPUT = 0x00007007;
- private static final int REQUEST_CODE_PASSPHRASE = 0x00007008;
- public static final String URI = "uri", NONCE = "nonce", TEXT = "text";
-
- LinkedIdWizard mLinkedIdWizard;
+ public static final String ARG_URI = "uri", ARG_TEXT = "text";
EditText mEditUri;
- ImageView mVerifyImage;
- View mVerifyProgress;
- TextView mVerifyStatus;
- int mResourceNonce;
URI mResourceUri;
String mResourceString;
- // This is a resource, set AFTER it has been verified
- LinkedCookieResource mVerifiedResource = null;
-
- /**
- * Creates new instance of this fragment
- */
public static LinkedIdCreateHttpsStep2Fragment newInstance
(String uri, int proofNonce, String proofText) {
LinkedIdCreateHttpsStep2Fragment frag = new LinkedIdCreateHttpsStep2Fragment();
Bundle args = new Bundle();
- args.putString(URI, uri);
- args.putInt(NONCE, proofNonce);
- args.putString(TEXT, proofText);
+ args.putInt(ARG_NONCE, proofNonce);
+ args.putString(ARG_URI, uri);
+ args.putString(ARG_TEXT, proofText);
frag.setArguments(args);
return frag;
}
+ @Override
GenericHttpsResource getResource() {
return GenericHttpsResource.createNew(mResourceUri);
}
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- final View view = inflater.inflate(R.layout.linked_create_https_fragment_step2, container, false);
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
- mResourceNonce = getArguments().getInt(NONCE);
+ try {
+ mResourceUri = new URI(getArguments().getString(ARG_URI));
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ getActivity().finish();
+ }
- view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- startCertify();
- }
- });
+ mResourceString = getArguments().getString(ARG_TEXT);
- view.findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- mLinkedIdWizard.loadFragment(null, null, LinkedIdWizard.FRAG_ACTION_TO_LEFT);
- }
- });
+ }
+
+ protected View newView(LayoutInflater inflater,
+ ViewGroup container, Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.linked_create_https_fragment_step2, container, false);
+ }
- mVerifyImage = (ImageView) view.findViewById(R.id.verify_image);
- mVerifyProgress = view.findViewById(R.id.verify_progress);
- mVerifyStatus = (TextView) view.findViewById(R.id.verify_status);
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View view = super.onCreateView(inflater, container, savedInstanceState);
view.findViewById(R.id.button_send).setOnClickListener(new OnClickListener() {
@Override
@@ -140,52 +109,12 @@ public class LinkedIdCreateHttpsStep2Fragment extends Fragment {
}
});
- view.findViewById(R.id.button_verify).setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- proofVerify();
- }
- });
-
- mResourceString = getArguments().getString(TEXT);
-
mEditUri = (EditText) view.findViewById(R.id.linked_create_https_uri);
mEditUri.setText(mResourceUri.toString());
- setVerifyProgress(false, null);
- mVerifyStatus.setText(R.string.linked_verify_pending);
-
return view;
}
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
-
- mLinkedIdWizard = (LinkedIdWizard) getActivity();
- }
-
- public void setVerifyProgress(boolean on, Boolean success) {
- mVerifyProgress.setVisibility(on ? View.VISIBLE : View.GONE);
- mVerifyImage.setVisibility(on ? View.GONE : View.VISIBLE);
- if (success == null) {
- mVerifyStatus.setText(R.string.linked_verifying);
- mVerifyImage.setImageResource(R.drawable.status_signature_unverified_cutout_24dp);
- mVerifyImage.setColorFilter(getResources().getColor(R.color.tertiary_text_light),
- PorterDuff.Mode.SRC_IN);
- } else if (success) {
- mVerifyStatus.setText(R.string.linked_verify_success);
- mVerifyImage.setImageResource(R.drawable.status_signature_verified_cutout_24dp);
- mVerifyImage.setColorFilter(getResources().getColor(R.color.android_green_dark),
- PorterDuff.Mode.SRC_IN);
- } else {
- mVerifyStatus.setText(R.string.linked_verify_error);
- mVerifyImage.setImageResource(R.drawable.status_signature_unknown_cutout_24dp);
- mVerifyImage.setColorFilter(getResources().getColor(R.color.android_red_dark),
- PorterDuff.Mode.SRC_IN);
- }
- }
-
private void proofSend () {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
@@ -226,124 +155,6 @@ public class LinkedIdCreateHttpsStep2Fragment extends Fragment {
}
}
- public void proofVerify() {
- setVerifyProgress(true, null);
-
- final LinkedCookieResource resource = getResource();
-
- new AsyncTask<Void,Void,LinkedVerifyResult>() {
-
- @Override
- protected LinkedVerifyResult doInBackground(Void... params) {
- return resource.verify(mLinkedIdWizard.mFingerprint, mResourceNonce);
- }
-
- @Override
- protected void onPostExecute(LinkedVerifyResult result) {
- super.onPostExecute(result);
- if (result.success()) {
- setVerifyProgress(false, true);
- mVerifiedResource = resource;
- } else {
- setVerifyProgress(false, false);
- // on error, show error message
- result.createNotify(getActivity()).show();
- }
- }
- }.execute();
-
- }
-
- public void startCertify() {
-
- if (mVerifiedResource == null) {
- Notify.showNotify(getActivity(), R.string.linked_need_verify, Notify.Style.ERROR);
- return;
- }
-
- Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class);
- intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, mLinkedIdWizard.mMasterKeyId);
- startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
-
- }
-
- public void certifyLinkedIdentity (String passphrase) {
- KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
- getActivity(),
- getString(R.string.progress_saving),
- ProgressDialog.STYLE_HORIZONTAL,
- true) {
- public void handleMessage(Message message) {
- // handle messages by standard KeychainIntentServiceHandler first
- super.handleMessage(message);
-
- if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
-
- // get returned data bundle
- Bundle returnData = message.getData();
- if (returnData == null) {
- return;
- }
- final OperationResult result =
- returnData.getParcelable(OperationResult.EXTRA_RESULT);
- if (result == null) {
- return;
- }
-
- // if bad -> display here!
- if (!result.success()) {
- result.createNotify(getActivity()).show();
- return;
- }
-
- result.createNotify(getActivity()).show();
-
- // if good -> finish, return result to showkey and display there!
- // Intent intent = new Intent();
- // intent.putExtra(OperationResult.EXTRA_RESULT, result);
- // getActivity().setResult(EditKeyActivity.RESULT_OK, intent);
-
- // AffirmationCreateHttpsStep3Fragment frag =
- // AffirmationCreateHttpsStep3Fragment.newInstance(
- // mResourceUri, mResourceNonce, mResourceString);
-
- // mAffirmationWizard.loadFragment(null, frag, AffirmationWizard.FRAG_ACTION_TO_RIGHT);
-
- }
- }
- };
-
- SaveKeyringParcel skp =
- new SaveKeyringParcel(mLinkedIdWizard.mMasterKeyId, mLinkedIdWizard.mFingerprint);
-
- WrappedUserAttribute ua =
- LinkedIdentity.fromResource(mVerifiedResource, mResourceNonce).toUserAttribute();
-
- skp.mAddUserAttribute.add(ua);
-
- // Send all information needed to service to import key in other thread
- Intent intent = new Intent(getActivity(), KeychainIntentService.class);
- intent.setAction(KeychainIntentService.ACTION_EDIT_KEYRING);
-
- // fill values for this action
- Bundle data = new Bundle();
- data.putString(KeychainIntentService.EDIT_KEYRING_PASSPHRASE, passphrase);
- data.putParcelable(KeychainIntentService.EDIT_KEYRING_PARCEL, skp);
- intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
-
- // Create a new Messenger for the communication back
- Messenger messenger = new Messenger(saveHandler);
- intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
-
- // show progress dialog
- saveHandler.showProgressDialog(getActivity());
-
- // start service with intent
- getActivity().startService(intent);
-
- }
-
-
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
@@ -355,15 +166,9 @@ public class LinkedIdCreateHttpsStep2Fragment extends Fragment {
Uri uri = data.getData();
saveFile(uri);
break;
- case REQUEST_CODE_PASSPHRASE:
- if (resultCode == Activity.RESULT_OK && data != null) {
- String passphrase =
- data.getStringExtra(PassphraseDialogActivity.MESSAGE_DATA_PASSPHRASE);
- certifyLinkedIdentity(passphrase);
- }
- break;
+ default:
+ super.onActivityResult(requestCode, resultCode, data);
}
- super.onActivityResult(requestCode, resultCode, data);
}
}