From 92b8d874ed0d7e8f835dbd8ce4205e74841d7162 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 15 Jan 2015 16:59:11 +0100 Subject: affirmation -> linked identity --- .../keychain/ui/ViewKeyMainFragment.java | 4 +- .../AffirmationCreateDnsStep1Fragment.java | 133 -------- .../AffirmationCreateDnsStep2Fragment.java | 360 -------------------- .../AffirmationCreateHttpsStep1Fragment.java | 132 -------- .../AffirmationCreateHttpsStep2Fragment.java | 368 --------------------- .../AffirmationCreateTwitterStep1Fragment.java | 140 -------- .../AffirmationCreateTwitterStep2Fragment.java | 150 --------- .../AffirmationCreateTwitterStep3Fragment.java | 250 -------------- .../ui/affirmations/AffirmationSelectFragment.java | 91 ----- .../ui/affirmations/AffirmationWizard.java | 98 ------ .../ui/linked/LinkedIdCreateDnsStep1Fragment.java | 133 ++++++++ .../ui/linked/LinkedIdCreateDnsStep2Fragment.java | 360 ++++++++++++++++++++ .../linked/LinkedIdCreateHttpsStep1Fragment.java | 132 ++++++++ .../linked/LinkedIdCreateHttpsStep2Fragment.java | 366 ++++++++++++++++++++ .../linked/LinkedIdCreateTwitterStep1Fragment.java | 134 ++++++++ .../linked/LinkedIdCreateTwitterStep2Fragment.java | 149 +++++++++ .../linked/LinkedIdCreateTwitterStep3Fragment.java | 235 +++++++++++++ .../keychain/ui/linked/LinkedIdSelectFragment.java | 91 +++++ .../keychain/ui/linked/LinkedIdWizard.java | 98 ++++++ 19 files changed, 1700 insertions(+), 1724 deletions(-) delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateDnsStep1Fragment.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateDnsStep2Fragment.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateHttpsStep1Fragment.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateHttpsStep2Fragment.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateTwitterStep1Fragment.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateTwitterStep2Fragment.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateTwitterStep3Fragment.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationSelectFragment.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationWizard.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep1Fragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep2Fragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep1Fragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep2Fragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep1Fragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep2Fragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep3Fragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdSelectFragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java index f40cfeb71..8101006e1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java @@ -38,7 +38,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; -import org.sufficientlysecure.keychain.ui.affirmations.AffirmationWizard; +import org.sufficientlysecure.keychain.ui.linked.LinkedIdWizard; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; @@ -361,7 +361,7 @@ public class ViewKeyMainFragment extends LoaderFragment implements } private void linkKey(Uri dataUri) { - Intent editIntent = new Intent(getActivity(), AffirmationWizard.class); + Intent editIntent = new Intent(getActivity(), LinkedIdWizard.class); editIntent.setData(KeyRings.buildUnifiedKeyRingUri(dataUri)); startActivityForResult(editIntent, 0); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateDnsStep1Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateDnsStep1Fragment.java deleted file mode 100644 index 70258eb5a..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateDnsStep1Fragment.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.ui.affirmations; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.Patterns; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.EditText; - -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.pgp.affirmation.LinkedIdentity; -import org.sufficientlysecure.keychain.pgp.affirmation.resources.DnsResource; - -public class AffirmationCreateDnsStep1Fragment extends Fragment { - - AffirmationWizard mAffirmationWizard; - - EditText mEditDns; - - /** - * Creates new instance of this fragment - */ - public static AffirmationCreateDnsStep1Fragment newInstance() { - AffirmationCreateDnsStep1Fragment frag = new AffirmationCreateDnsStep1Fragment(); - - Bundle args = new Bundle(); - frag.setArguments(args); - - return frag; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - mAffirmationWizard = (AffirmationWizard) getActivity(); - - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final View view = inflater.inflate(R.layout.affirmation_create_dns_fragment_step1, container, false); - - view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - - String uri = mEditDns.getText().toString(); - - if (!checkUri(uri)) { - mEditDns.setError("Please enter a valid domain name!"); - return; - } - - String proofNonce = LinkedIdentity.generateNonce(); - String proofText = DnsResource.generateText(getActivity(), - mAffirmationWizard.mFingerprint, proofNonce); - - AffirmationCreateDnsStep2Fragment frag = - AffirmationCreateDnsStep2Fragment.newInstance(uri, proofNonce, proofText); - - mAffirmationWizard.loadFragment(null, frag, AffirmationWizard.FRAG_ACTION_TO_RIGHT); - - } - }); - - view.findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mAffirmationWizard.loadFragment(null, null, AffirmationWizard.FRAG_ACTION_TO_LEFT); - } - }); - - mEditDns = (EditText) view.findViewById(R.id.affirmation_create_dns_domain); - - mEditDns.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { - } - - @Override - public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { - } - - @Override - public void afterTextChanged(Editable editable) { - String uri = editable.toString(); - if (uri.length() > 0) { - if (checkUri(uri)) { - mEditDns.setCompoundDrawablesWithIntrinsicBounds(0, 0, - R.drawable.uid_mail_ok, 0); - } else { - mEditDns.setCompoundDrawablesWithIntrinsicBounds(0, 0, - R.drawable.uid_mail_bad, 0); - } - } else { - // remove drawable if email is empty - mEditDns.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - } - } - }); - - mEditDns.setText("mugenguild.com"); - - return view; - } - - private static boolean checkUri(String uri) { - return Patterns.DOMAIN_NAME.matcher(uri).matches(); - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateDnsStep2Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateDnsStep2Fragment.java deleted file mode 100644 index 87568ddc2..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateDnsStep2Fragment.java +++ /dev/null @@ -1,360 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.ui.affirmations; - -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.affirmation.LinkedIdentity; -import org.sufficientlysecure.keychain.pgp.affirmation.resources.DnsResource; -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; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.PrintWriter; - -public class AffirmationCreateDnsStep2Fragment extends Fragment { - - private static final int REQUEST_CODE_OUTPUT = 0x00007007; - private static final int REQUEST_CODE_PASSPHRASE = 0x00007008; - - public static final String DOMAIN = "domain", NONCE = "nonce", TEXT = "text"; - - AffirmationWizard mAffirmationWizard; - - EditText mEditUri; - ImageView mVerifyImage; - View mVerifyProgress; - TextView mVerifyStatus; - - String mResourceDomain; - String mResourceNonce, mResourceString; - - // This is a resource, set AFTER it has been verified - DnsResource mVerifiedResource = null; - - /** - * Creates new instance of this fragment - */ - public static AffirmationCreateDnsStep2Fragment newInstance - (String uri, String proofNonce, String proofText) { - - AffirmationCreateDnsStep2Fragment frag = new AffirmationCreateDnsStep2Fragment(); - - Bundle args = new Bundle(); - args.putString(DOMAIN, uri); - args.putString(NONCE, proofNonce); - args.putString(TEXT, proofText); - frag.setArguments(args); - - return frag; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final View view = inflater.inflate(R.layout.affirmation_create_dns_fragment_step2, container, false); - - mResourceDomain = getArguments().getString(DOMAIN); - mResourceNonce = getArguments().getString(NONCE); - mResourceString = getArguments().getString(TEXT); - - view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - startCertify(); - } - }); - - view.findViewById(R.id.back_button).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - mAffirmationWizard.loadFragment(null, null, AffirmationWizard.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_send).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - proofSend(); - } - }); - - view.findViewById(R.id.button_save).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - proofSave(); - } - }); - - view.findViewById(R.id.button_verify).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - proofVerify(); - } - }); - - mEditUri = (EditText) view.findViewById(R.id.affirmation_create_dns_text); - mEditUri.setText(mResourceString); - - setVerifyProgress(false, null); - mVerifyStatus.setText(R.string.linked_verify_pending); - - return view; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - mAffirmationWizard = (AffirmationWizard) 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); - 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); - 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); - 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); - sendIntent.putExtra(Intent.EXTRA_TEXT, mResourceString); - sendIntent.setType("text/plain"); - startActivity(sendIntent); - } - - private void proofSave () { - String state = Environment.getExternalStorageState(); - if (!Environment.MEDIA_MOUNTED.equals(state)) { - Notify.showNotify(getActivity(), "External storage not available!", Style.ERROR); - return; - } - - String targetName = "pgpkey.txt"; - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - File targetFile = new File(Constants.Path.APP_DIR, targetName); - FileHelper.saveFile(this, getString(R.string.title_decrypt_to_file), - getString(R.string.specify_file_to_decrypt_to), targetFile, REQUEST_CODE_OUTPUT); - } else { - FileHelper.saveDocument(this, "text/plain", targetName, REQUEST_CODE_OUTPUT); - } - } - - private void saveFile(Uri uri) { - try { - PrintWriter out = - new PrintWriter(getActivity().getContentResolver().openOutputStream(uri)); - out.print(mResourceString); - if (out.checkError()) { - Notify.showNotify(getActivity(), "Error writing file!", Style.ERROR); - } - } catch (FileNotFoundException e) { - Notify.showNotify(getActivity(), "File could not be opened for writing!", Style.ERROR); - e.printStackTrace(); - } - } - - public void proofVerify() { - setVerifyProgress(true, null); - - final DnsResource resource = DnsResource.createNew(mResourceDomain); - - new AsyncTask() { - - @Override - protected LinkedVerifyResult doInBackground(Void... params) { - return resource.verify(mAffirmationWizard.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, Style.ERROR); - return; - } - - Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class); - intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, mAffirmationWizard.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( - // mResourceDomain, mResourceNonce, mResourceString); - - // mAffirmationWizard.loadFragment(null, frag, AffirmationWizard.FRAG_ACTION_TO_RIGHT); - - } - } - }; - - SaveKeyringParcel skp = - new SaveKeyringParcel(mAffirmationWizard.mMasterKeyId, mAffirmationWizard.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) { - // For saving a file - case REQUEST_CODE_OUTPUT: - if (data == null) { - return; - } - 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; - } - super.onActivityResult(requestCode, resultCode, data); - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateHttpsStep1Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateHttpsStep1Fragment.java deleted file mode 100644 index 2b00d7483..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateHttpsStep1Fragment.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.ui.affirmations; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.Patterns; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.EditText; - -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.pgp.affirmation.LinkedIdentity; -import org.sufficientlysecure.keychain.pgp.affirmation.resources.GenericHttpsResource; - -public class AffirmationCreateHttpsStep1Fragment extends Fragment { - - AffirmationWizard mAffirmationWizard; - - EditText mEditUri; - - /** - * Creates new instance of this fragment - */ - public static AffirmationCreateHttpsStep1Fragment newInstance() { - AffirmationCreateHttpsStep1Fragment frag = new AffirmationCreateHttpsStep1Fragment(); - - Bundle args = new Bundle(); - frag.setArguments(args); - - return frag; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - mAffirmationWizard = (AffirmationWizard) getActivity(); - - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final View view = inflater.inflate(R.layout.affirmation_create_https_fragment_step1, container, false); - - view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - - String uri = "https://" + mEditUri.getText(); - - if (!checkUri(uri)) { - return; - } - - String proofNonce = LinkedIdentity.generateNonce(); - String proofText = GenericHttpsResource.generateText(getActivity(), - mAffirmationWizard.mFingerprint, proofNonce); - - AffirmationCreateHttpsStep2Fragment frag = - AffirmationCreateHttpsStep2Fragment.newInstance(uri, proofNonce, proofText); - - mAffirmationWizard.loadFragment(null, frag, AffirmationWizard.FRAG_ACTION_TO_RIGHT); - - } - }); - - view.findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mAffirmationWizard.loadFragment(null, null, AffirmationWizard.FRAG_ACTION_TO_LEFT); - } - }); - - mEditUri = (EditText) view.findViewById(R.id.affirmation_create_https_uri); - - mEditUri.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { - } - - @Override - public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { - } - - @Override - public void afterTextChanged(Editable editable) { - String uri = "https://" + editable; - if (uri.length() > 0) { - if (checkUri(uri)) { - mEditUri.setCompoundDrawablesWithIntrinsicBounds(0, 0, - R.drawable.uid_mail_ok, 0); - } else { - mEditUri.setCompoundDrawablesWithIntrinsicBounds(0, 0, - R.drawable.uid_mail_bad, 0); - } - } else { - // remove drawable if email is empty - mEditUri.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - } - } - }); - - mEditUri.setText("mugenguild.com/pgpkey.txt"); - - return view; - } - - private static boolean checkUri(String uri) { - return Patterns.WEB_URL.matcher(uri).matches(); - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateHttpsStep2Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateHttpsStep2Fragment.java deleted file mode 100644 index eb1088989..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateHttpsStep2Fragment.java +++ /dev/null @@ -1,368 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.ui.affirmations; - -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.affirmation.LinkedIdentity; -import org.sufficientlysecure.keychain.pgp.affirmation.resources.GenericHttpsResource; -import org.sufficientlysecure.keychain.service.KeychainIntentService; -import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.PassphraseCacheService; -import org.sufficientlysecure.keychain.service.SaveKeyringParcel; -import org.sufficientlysecure.keychain.ui.EditKeyActivity; -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; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.PrintWriter; -import java.net.URI; -import java.net.URISyntaxException; - -public class AffirmationCreateHttpsStep2Fragment extends Fragment { - - 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"; - - AffirmationWizard mAffirmationWizard; - - EditText mEditUri; - ImageView mVerifyImage; - View mVerifyProgress; - TextView mVerifyStatus; - - String mResourceUri; - String mResourceNonce, mResourceString; - - // This is a resource, set AFTER it has been verified - GenericHttpsResource mVerifiedResource = null; - - /** - * Creates new instance of this fragment - */ - public static AffirmationCreateHttpsStep2Fragment newInstance - (String uri, String proofNonce, String proofText) { - - AffirmationCreateHttpsStep2Fragment frag = new AffirmationCreateHttpsStep2Fragment(); - - Bundle args = new Bundle(); - args.putString(URI, uri); - args.putString(NONCE, proofNonce); - args.putString(TEXT, proofText); - frag.setArguments(args); - - return frag; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final View view = inflater.inflate(R.layout.affirmation_create_https_fragment_step2, container, false); - - mResourceUri = getArguments().getString(URI); - mResourceNonce = getArguments().getString(NONCE); - mResourceString = getArguments().getString(TEXT); - - 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) { - mAffirmationWizard.loadFragment(null, null, AffirmationWizard.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_send).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - proofSend(); - } - }); - - view.findViewById(R.id.button_save).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - proofSave(); - } - }); - - view.findViewById(R.id.button_verify).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - proofVerify(); - } - }); - - mEditUri = (EditText) view.findViewById(R.id.affirmation_create_https_uri); - mEditUri.setText(mResourceUri); - - setVerifyProgress(false, null); - mVerifyStatus.setText(R.string.linked_verify_pending); - - return view; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - mAffirmationWizard = (AffirmationWizard) 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); - 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); - 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); - 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); - sendIntent.putExtra(Intent.EXTRA_TEXT, mResourceString); - sendIntent.setType("text/plain"); - startActivity(sendIntent); - } - - private void proofSave () { - String state = Environment.getExternalStorageState(); - if (!Environment.MEDIA_MOUNTED.equals(state)) { - Notify.showNotify(getActivity(), "External storage not available!", Style.ERROR); - return; - } - - String targetName = "pgpkey.txt"; - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - File targetFile = new File(Constants.Path.APP_DIR, targetName); - FileHelper.saveFile(this, getString(R.string.title_decrypt_to_file), - getString(R.string.specify_file_to_decrypt_to), targetFile, REQUEST_CODE_OUTPUT); - } else { - FileHelper.saveDocument(this, "text/plain", targetName, REQUEST_CODE_OUTPUT); - } - } - - private void saveFile(Uri uri) { - try { - PrintWriter out = - new PrintWriter(getActivity().getContentResolver().openOutputStream(uri)); - out.print(mResourceString); - if (out.checkError()) { - Notify.showNotify(getActivity(), "Error writing file!", Style.ERROR); - } - } catch (FileNotFoundException e) { - Notify.showNotify(getActivity(), "File could not be opened for writing!", Style.ERROR); - e.printStackTrace(); - } - } - - public void proofVerify() { - setVerifyProgress(true, null); - - try { - final GenericHttpsResource resource = GenericHttpsResource.createNew(new URI(mResourceUri)); - - new AsyncTask() { - - @Override - protected LinkedVerifyResult doInBackground(Void... params) { - return resource.verify(mAffirmationWizard.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(); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - - } - - 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, mAffirmationWizard.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(mAffirmationWizard.mMasterKeyId, mAffirmationWizard.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) { - // For saving a file - case REQUEST_CODE_OUTPUT: - if (data == null) { - return; - } - 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; - } - super.onActivityResult(requestCode, resultCode, data); - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateTwitterStep1Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateTwitterStep1Fragment.java deleted file mode 100644 index f52a18807..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateTwitterStep1Fragment.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.ui.affirmations; - -import android.os.AsyncTask; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.Patterns; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.EditText; - -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.pgp.affirmation.LinkedIdentity; -import org.sufficientlysecure.keychain.pgp.affirmation.resources.GenericHttpsResource; -import org.sufficientlysecure.keychain.pgp.affirmation.resources.TwitterResource; -import org.sufficientlysecure.keychain.ui.CreateKeyActivity; -import org.sufficientlysecure.keychain.ui.util.Notify; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; - -public class AffirmationCreateTwitterStep1Fragment extends Fragment { - - AffirmationWizard mAffirmationWizard; - - EditText mEditHandle; - - /** - * Creates new instance of this fragment - */ - public static AffirmationCreateTwitterStep1Fragment newInstance() { - AffirmationCreateTwitterStep1Fragment frag = new AffirmationCreateTwitterStep1Fragment(); - - Bundle args = new Bundle(); - frag.setArguments(args); - - return frag; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - mAffirmationWizard = (AffirmationWizard) getActivity(); - - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final View view = inflater.inflate(R.layout.affirmation_create_twitter_fragment_step1, container, false); - - view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - - final String handle = mEditHandle.getText().toString(); - - new AsyncTask() { - - @Override - protected Boolean doInBackground(Void... params) { - return true; // checkHandle(handle); - } - - @Override - protected void onPostExecute(Boolean result) { - super.onPostExecute(result); - - if (result == null) { - Notify.showNotify(getActivity(), "Connection error while checking username!", Notify.Style.ERROR); - return; - } - - if (!result) { - Notify.showNotify(getActivity(), "This handle does not exist on Twitter!", Notify.Style.ERROR); - return; - } - - String proofNonce = LinkedIdentity.generateNonce(); - String proofText = TwitterResource.generateText(getActivity(), - mAffirmationWizard.mFingerprint, proofNonce); - - AffirmationCreateTwitterStep2Fragment frag = - AffirmationCreateTwitterStep2Fragment.newInstance(handle, proofNonce, proofText); - - mAffirmationWizard.loadFragment(null, frag, AffirmationWizard.FRAG_ACTION_TO_RIGHT); - } - }.execute(); - - } - }); - - view.findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mAffirmationWizard.loadFragment(null, null, AffirmationWizard.FRAG_ACTION_TO_LEFT); - } - }); - - mEditHandle = (EditText) view.findViewById(R.id.linked_create_twitter_handle); - mEditHandle.setText("Valodim"); - - return view; - } - - private static Boolean checkHandle(String handle) { - try { - HttpURLConnection nection = - (HttpURLConnection) new URL("https://twitter.com/" + handle).openConnection(); - nection.setRequestMethod("HEAD"); - return nection.getResponseCode() == 200; - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateTwitterStep2Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateTwitterStep2Fragment.java deleted file mode 100644 index e12d2f86b..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateTwitterStep2Fragment.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.ui.affirmations; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.InputFilter; -import android.text.TextWatcher; -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.R; -import org.sufficientlysecure.keychain.ui.CreateKeyActivity; - -public class AffirmationCreateTwitterStep2Fragment extends Fragment { - - private static final int REQUEST_CODE_OUTPUT = 0x00007007; - - public static final String HANDLE = "uri", NONCE = "nonce", TEXT = "text"; - - AffirmationWizard mAffirmationWizard; - - EditText mEditTweetCustom, mEditTweetPreview; - ImageView mVerifyImage; - View mVerifyProgress; - TextView mVerifyStatus, mEditTweetTextLen; - - String mResourceHandle; - String mResourceNonce, mResourceString; - - /** - * Creates new instance of this fragment - */ - public static AffirmationCreateTwitterStep2Fragment newInstance - (String handle, String proofNonce, String proofText) { - - AffirmationCreateTwitterStep2Fragment frag = new AffirmationCreateTwitterStep2Fragment(); - - Bundle args = new Bundle(); - args.putString(HANDLE, handle); - args.putString(NONCE, proofNonce); - args.putString(TEXT, proofText); - frag.setArguments(args); - - return frag; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final View view = inflater.inflate(R.layout.affirmation_create_twitter_fragment_step2, container, false); - - mResourceHandle = getArguments().getString(HANDLE); - mResourceNonce = getArguments().getString(NONCE); - mResourceString = getArguments().getString(TEXT); - - view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - - AffirmationCreateTwitterStep3Fragment frag = - AffirmationCreateTwitterStep3Fragment.newInstance(mResourceHandle, - mResourceNonce, mResourceString, - mEditTweetCustom.getText().toString()); - - mAffirmationWizard.loadFragment(null, frag, AffirmationWizard.FRAG_ACTION_TO_RIGHT); - } - }); - - view.findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mAffirmationWizard.loadFragment(null, null, AffirmationWizard.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); - - mEditTweetPreview = (EditText) view.findViewById(R.id.linked_create_twitter_preview); - mEditTweetPreview.setText(mResourceString); - - mEditTweetCustom = (EditText) view.findViewById(R.id.linked_create_twitter_custom); - mEditTweetCustom.setFilters(new InputFilter[] { - new InputFilter.LengthFilter(139 - mResourceString.length()) - }); - - mEditTweetTextLen = (TextView) view.findViewById(R.id.linked_create_twitter_textlen); - mEditTweetTextLen.setText(mResourceString.length() + "/140"); - - mEditTweetCustom.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { - } - - @Override - public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { - } - - @Override - public void afterTextChanged(Editable editable) { - if (editable != null && editable.length() > 0) { - String str = editable + " " + mResourceString; - mEditTweetPreview.setText(str); - - mEditTweetTextLen.setText(str.length() + "/140"); - mEditTweetTextLen.setTextColor(getResources().getColor(str.length() == 140 - ? R.color.android_red_dark - : R.color.primary_dark_material_light)); - - - } else { - mEditTweetPreview.setText(mResourceString); - mEditTweetTextLen.setText(mResourceString.length() + "/140"); - } - } - }); - - return view; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - mAffirmationWizard = (AffirmationWizard) getActivity(); - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateTwitterStep3Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateTwitterStep3Fragment.java deleted file mode 100644 index 5ceda3342..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationCreateTwitterStep3Fragment.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.ui.affirmations; - -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -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.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.pgp.affirmation.resources.GenericHttpsResource; -import org.sufficientlysecure.keychain.pgp.affirmation.resources.TwitterResource; -import org.sufficientlysecure.keychain.ui.util.Notify; -import org.sufficientlysecure.keychain.ui.util.Notify.Style; -import org.sufficientlysecure.keychain.util.FileHelper; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.PrintWriter; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; - -public class AffirmationCreateTwitterStep3Fragment extends Fragment { - - public static final String HANDLE = "uri", NONCE = "nonce", TEXT = "text", CUSTOM = "custom"; - - AffirmationWizard mAffirmationWizard; - - EditText mEditTweetPreview; - ImageView mVerifyImage; - View mVerifyProgress; - TextView mVerifyStatus; - - String mResourceHandle, mCustom, mFullString; - String mResourceNonce, mResourceString; - - /** - * Creates new instance of this fragment - */ - public static AffirmationCreateTwitterStep3Fragment newInstance - (String handle, String proofNonce, String proofText, String customText) { - - AffirmationCreateTwitterStep3Fragment frag = new AffirmationCreateTwitterStep3Fragment(); - - Bundle args = new Bundle(); - args.putString(HANDLE, handle); - args.putString(NONCE, proofNonce); - args.putString(TEXT, proofText); - args.putString(CUSTOM, customText); - frag.setArguments(args); - - return frag; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final View view = inflater.inflate(R.layout.affirmation_create_twitter_fragment_step3, container, false); - - mResourceHandle = getArguments().getString(HANDLE); - mResourceNonce = getArguments().getString(NONCE); - mResourceString = getArguments().getString(TEXT); - mCustom = getArguments().getString(CUSTOM); - - mFullString = mCustom.isEmpty() ? mResourceString : (mCustom + " " + mResourceString); - - mVerifyImage = (ImageView) view.findViewById(R.id.verify_image); - mVerifyProgress = view.findViewById(R.id.verify_progress); - mVerifyStatus = (TextView) view.findViewById(R.id.verify_status); - - mEditTweetPreview = (EditText) view.findViewById(R.id.linked_create_twitter_preview); - mEditTweetPreview.setText(mFullString); - - view.findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mAffirmationWizard.loadFragment(null, null, AffirmationWizard.FRAG_ACTION_TO_LEFT); - } - }); - - view.findViewById(R.id.button_send).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - proofSend(); - } - }); - - view.findViewById(R.id.button_share).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - proofShare(); - } - }); - - 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); - - - view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - - // AffirmationCreateHttpsStep2Fragment frag = - // AffirmationCreateHttpsStep2Fragment.newInstance(); - - // mAffirmationWizard.loadFragment(null, frag, AffirmationWizard.FRAG_ACTION_TO_RIGHT); - } - }); - - return view; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - mAffirmationWizard = (AffirmationWizard) 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); - 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); - 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); - mVerifyImage.setColorFilter(getResources().getColor(R.color.android_red_dark), - PorterDuff.Mode.SRC_IN); - } - } - - public void proofVerify() { - setVerifyProgress(true, null); - - /* - try { - final TwitterResource resource = TwitterResource.createNew(new URI(mResourceHandle)); - - new AsyncTask() { - - @Override - protected LinkedVerifyResult doInBackground(Void... params) { - return resource.verify(mAffirmationWizard.mFingerprint, mResourceNonce); - } - - @Override - protected void onPostExecute(LinkedVerifyResult result) { - super.onPostExecute(result); - if (result.success()) { - setVerifyProgress(false, true); - } else { - setVerifyProgress(false, false); - // on error, show error message - result.createNotify(getActivity()).show(); - } - } - }.execute(); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - */ - - } - - private void proofShare() { - Intent sendIntent = new Intent(); - sendIntent.setAction(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_TEXT, mFullString); - sendIntent.setType("text/plain"); - startActivity(sendIntent); - } - - private void proofSend() { - - Intent tweetIntent = new Intent(Intent.ACTION_SEND); - tweetIntent.putExtra(Intent.EXTRA_TEXT, mFullString); - tweetIntent.setType("text/plain"); - - PackageManager packManager = getActivity().getPackageManager(); - List resolvedInfoList = packManager.queryIntentActivities(tweetIntent, - PackageManager.MATCH_DEFAULT_ONLY); - - boolean resolved = false; - for(ResolveInfo resolveInfo : resolvedInfoList){ - if(resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) { - tweetIntent.setClassName( - resolveInfo.activityInfo.packageName, - resolveInfo.activityInfo.name ); - resolved = true; - break; - } - } - - if (resolved) { - startActivity(tweetIntent); - } else { - Notify.showNotify(getActivity(), - "Twitter app is not installed, please use the send intent!", - Notify.Style.ERROR); - } - - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationSelectFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationSelectFragment.java deleted file mode 100644 index c3667b5a2..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationSelectFragment.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.ui.affirmations; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import org.sufficientlysecure.keychain.R; - -public class AffirmationSelectFragment extends Fragment { - - AffirmationWizard mAffirmationWizard; - - /** - * Creates new instance of this fragment - */ - public static AffirmationSelectFragment newInstance() { - AffirmationSelectFragment frag = new AffirmationSelectFragment(); - - Bundle args = new Bundle(); - frag.setArguments(args); - - return frag; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.affirmation_select_fragment, container, false); - - view.findViewById(R.id.affirmation_create_https_button) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - AffirmationCreateHttpsStep1Fragment frag = - AffirmationCreateHttpsStep1Fragment.newInstance(); - - mAffirmationWizard.loadFragment(null, frag, AffirmationWizard.FRAG_ACTION_TO_RIGHT); - } - }); - - view.findViewById(R.id.affirmation_create_dns_button) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - AffirmationCreateDnsStep1Fragment frag = - AffirmationCreateDnsStep1Fragment.newInstance(); - - mAffirmationWizard.loadFragment(null, frag, AffirmationWizard.FRAG_ACTION_TO_RIGHT); - } - }); - - view.findViewById(R.id.affirmation_create_twitter_button) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - AffirmationCreateTwitterStep1Fragment frag = - AffirmationCreateTwitterStep1Fragment.newInstance(); - - mAffirmationWizard.loadFragment(null, frag, AffirmationWizard.FRAG_ACTION_TO_RIGHT); - } - }); - - return view; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - mAffirmationWizard = (AffirmationWizard) getActivity(); - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationWizard.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationWizard.java deleted file mode 100644 index 99b88405a..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/affirmations/AffirmationWizard.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.ui.affirmations; - -import android.net.Uri; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentTransaction; -import android.support.v7.app.ActionBarActivity; - -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.util.Log; - -public class AffirmationWizard extends ActionBarActivity { - - public static final int FRAG_ACTION_START = 0; - public static final int FRAG_ACTION_TO_RIGHT = 1; - public static final int FRAG_ACTION_TO_LEFT = 2; - - long mMasterKeyId; - byte[] mFingerprint; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.create_key_activity); - - try { - Uri uri = getIntent().getData(); - CachedPublicKeyRing ring = new ProviderHelper(this).getCachedPublicKeyRing(uri); - mMasterKeyId = ring.extractOrGetMasterKeyId(); - mFingerprint = ring.getFingerprint(); - } catch (PgpKeyNotFoundException e) { - Log.e(Constants.TAG, "Invalid uri given, key does not exist!"); - finish(); - return; - } - - // pass extras into fragment - AffirmationSelectFragment frag = AffirmationSelectFragment.newInstance(); - loadFragment(null, frag, FRAG_ACTION_START); - } - - public void loadFragment(Bundle savedInstanceState, Fragment fragment, int action) { - // However, if we're being restored from a previous state, - // then we don't need to do anything and should return or else - // we could end up with overlapping fragments. - if (savedInstanceState != null) { - return; - } - - // Add the fragment to the 'fragment_container' FrameLayout - // NOTE: We use commitAllowingStateLoss() to prevent weird crashes! - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - - switch (action) { - case FRAG_ACTION_START: - transaction.setCustomAnimations(0, 0); - transaction.replace(R.id.create_key_fragment_container, fragment) - .commitAllowingStateLoss(); - break; - case FRAG_ACTION_TO_LEFT: - getSupportFragmentManager().popBackStackImmediate(); - break; - case FRAG_ACTION_TO_RIGHT: - transaction.setCustomAnimations(R.anim.frag_slide_in_from_right, R.anim.frag_slide_out_to_left, - R.anim.frag_slide_in_from_left, R.anim.frag_slide_out_to_right); - transaction.addToBackStack(null); - transaction.replace(R.id.create_key_fragment_container, fragment) - .commitAllowingStateLoss(); - break; - - } - // do it immediately! - getSupportFragmentManager().executePendingTransactions(); - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep1Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep1Fragment.java new file mode 100644 index 000000000..ba57ace4b --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep1Fragment.java @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui.linked; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Patterns; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.EditText; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.linked.LinkedIdentity; +import org.sufficientlysecure.keychain.pgp.linked.resources.DnsResource; + +public class LinkedIdCreateDnsStep1Fragment extends Fragment { + + LinkedIdWizard mLinkedIdWizard; + + EditText mEditDns; + + /** + * Creates new instance of this fragment + */ + public static LinkedIdCreateDnsStep1Fragment newInstance() { + LinkedIdCreateDnsStep1Fragment frag = new LinkedIdCreateDnsStep1Fragment(); + + Bundle args = new Bundle(); + frag.setArguments(args); + + return frag; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + mLinkedIdWizard = (LinkedIdWizard) getActivity(); + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.linked_create_dns_fragment_step1, container, false); + + view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + + String uri = mEditDns.getText().toString(); + + if (!checkUri(uri)) { + mEditDns.setError("Please enter a valid domain name!"); + return; + } + + String proofNonce = LinkedIdentity.generateNonce(); + String proofText = DnsResource.generateText(getActivity(), + mLinkedIdWizard.mFingerprint, proofNonce); + + LinkedIdCreateDnsStep2Fragment frag = + LinkedIdCreateDnsStep2Fragment.newInstance(uri, proofNonce, proofText); + + mLinkedIdWizard.loadFragment(null, frag, LinkedIdWizard.FRAG_ACTION_TO_RIGHT); + + } + }); + + 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); + } + }); + + mEditDns = (EditText) view.findViewById(R.id.linked_create_dns_domain); + + mEditDns.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { + } + + @Override + public void afterTextChanged(Editable editable) { + String uri = editable.toString(); + if (uri.length() > 0) { + if (checkUri(uri)) { + mEditDns.setCompoundDrawablesWithIntrinsicBounds(0, 0, + R.drawable.uid_mail_ok, 0); + } else { + mEditDns.setCompoundDrawablesWithIntrinsicBounds(0, 0, + R.drawable.uid_mail_bad, 0); + } + } else { + // remove drawable if email is empty + mEditDns.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + } + } + }); + + mEditDns.setText("mugenguild.com"); + + return view; + } + + private static boolean checkUri(String uri) { + return Patterns.DOMAIN_NAME.matcher(uri).matches(); + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep2Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep2Fragment.java new file mode 100644 index 000000000..ff8d03dd4 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep2Fragment.java @@ -0,0 +1,360 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +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.LinkedIdentity; +import org.sufficientlysecure.keychain.pgp.linked.resources.DnsResource; +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; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; + +public class LinkedIdCreateDnsStep2Fragment extends Fragment { + + private static final int REQUEST_CODE_OUTPUT = 0x00007007; + private static final int REQUEST_CODE_PASSPHRASE = 0x00007008; + + public static final String DOMAIN = "domain", NONCE = "nonce", TEXT = "text"; + + LinkedIdWizard mLinkedIdWizard; + + EditText mEditUri; + ImageView mVerifyImage; + View mVerifyProgress; + TextView mVerifyStatus; + + String mResourceDomain; + String mResourceNonce, mResourceString; + + // This is a resource, set AFTER it has been verified + DnsResource mVerifiedResource = null; + + /** + * Creates new instance of this fragment + */ + public static LinkedIdCreateDnsStep2Fragment newInstance + (String uri, String proofNonce, String proofText) { + + LinkedIdCreateDnsStep2Fragment frag = new LinkedIdCreateDnsStep2Fragment(); + + Bundle args = new Bundle(); + args.putString(DOMAIN, uri); + args.putString(NONCE, proofNonce); + args.putString(TEXT, proofText); + frag.setArguments(args); + + return frag; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.linked_create_dns_fragment_step2, container, false); + + mResourceDomain = getArguments().getString(DOMAIN); + mResourceNonce = getArguments().getString(NONCE); + mResourceString = getArguments().getString(TEXT); + + view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + startCertify(); + } + }); + + view.findViewById(R.id.back_button).setOnClickListener(new 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_send).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + proofSend(); + } + }); + + view.findViewById(R.id.button_save).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + proofSave(); + } + }); + + view.findViewById(R.id.button_verify).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + proofVerify(); + } + }); + + mEditUri = (EditText) view.findViewById(R.id.linked_create_dns_text); + mEditUri.setText(mResourceString); + + 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); + 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); + 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); + 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); + sendIntent.putExtra(Intent.EXTRA_TEXT, mResourceString); + sendIntent.setType("text/plain"); + startActivity(sendIntent); + } + + private void proofSave () { + String state = Environment.getExternalStorageState(); + if (!Environment.MEDIA_MOUNTED.equals(state)) { + Notify.showNotify(getActivity(), "External storage not available!", Style.ERROR); + return; + } + + String targetName = "pgpkey.txt"; + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { + File targetFile = new File(Constants.Path.APP_DIR, targetName); + FileHelper.saveFile(this, getString(R.string.title_decrypt_to_file), + getString(R.string.specify_file_to_decrypt_to), targetFile, REQUEST_CODE_OUTPUT); + } else { + FileHelper.saveDocument(this, "text/plain", targetName, REQUEST_CODE_OUTPUT); + } + } + + private void saveFile(Uri uri) { + try { + PrintWriter out = + new PrintWriter(getActivity().getContentResolver().openOutputStream(uri)); + out.print(mResourceString); + if (out.checkError()) { + Notify.showNotify(getActivity(), "Error writing file!", Style.ERROR); + } + } catch (FileNotFoundException e) { + Notify.showNotify(getActivity(), "File could not be opened for writing!", Style.ERROR); + e.printStackTrace(); + } + } + + public void proofVerify() { + setVerifyProgress(true, null); + + final DnsResource resource = DnsResource.createNew(mResourceDomain); + + new AsyncTask() { + + @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, 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( + // mResourceDomain, 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) { + // For saving a file + case REQUEST_CODE_OUTPUT: + if (data == null) { + return; + } + 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; + } + super.onActivityResult(requestCode, resultCode, data); + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep1Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep1Fragment.java new file mode 100644 index 000000000..7c5f1f032 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep1Fragment.java @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui.linked; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Patterns; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.EditText; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.linked.LinkedIdentity; +import org.sufficientlysecure.keychain.pgp.linked.resources.GenericHttpsResource; + +public class LinkedIdCreateHttpsStep1Fragment extends Fragment { + + LinkedIdWizard mLinkedIdWizard; + + EditText mEditUri; + + /** + * Creates new instance of this fragment + */ + public static LinkedIdCreateHttpsStep1Fragment newInstance() { + LinkedIdCreateHttpsStep1Fragment frag = new LinkedIdCreateHttpsStep1Fragment(); + + Bundle args = new Bundle(); + frag.setArguments(args); + + return frag; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + mLinkedIdWizard = (LinkedIdWizard) getActivity(); + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.linked_create_https_fragment_step1, container, false); + + view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + + String uri = "https://" + mEditUri.getText(); + + if (!checkUri(uri)) { + return; + } + + String proofNonce = LinkedIdentity.generateNonce(); + String proofText = GenericHttpsResource.generateText(getActivity(), + mLinkedIdWizard.mFingerprint, proofNonce); + + LinkedIdCreateHttpsStep2Fragment frag = + LinkedIdCreateHttpsStep2Fragment.newInstance(uri, proofNonce, proofText); + + mLinkedIdWizard.loadFragment(null, frag, LinkedIdWizard.FRAG_ACTION_TO_RIGHT); + + } + }); + + 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); + } + }); + + mEditUri = (EditText) view.findViewById(R.id.linked_create_https_uri); + + mEditUri.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { + } + + @Override + public void afterTextChanged(Editable editable) { + String uri = "https://" + editable; + if (uri.length() > 0) { + if (checkUri(uri)) { + mEditUri.setCompoundDrawablesWithIntrinsicBounds(0, 0, + R.drawable.uid_mail_ok, 0); + } else { + mEditUri.setCompoundDrawablesWithIntrinsicBounds(0, 0, + R.drawable.uid_mail_bad, 0); + } + } else { + // remove drawable if email is empty + mEditUri.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + } + } + }); + + mEditUri.setText("mugenguild.com/pgpkey.txt"); + + return view; + } + + private static boolean checkUri(String uri) { + return Patterns.WEB_URL.matcher(uri).matches(); + } + +} 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 new file mode 100644 index 000000000..0d78bad27 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep2Fragment.java @@ -0,0 +1,366 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +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.LinkedIdentity; +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; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.net.URI; +import java.net.URISyntaxException; + +public class LinkedIdCreateHttpsStep2Fragment extends Fragment { + + 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; + + EditText mEditUri; + ImageView mVerifyImage; + View mVerifyProgress; + TextView mVerifyStatus; + + String mResourceUri; + String mResourceNonce, mResourceString; + + // This is a resource, set AFTER it has been verified + GenericHttpsResource mVerifiedResource = null; + + /** + * Creates new instance of this fragment + */ + public static LinkedIdCreateHttpsStep2Fragment newInstance + (String uri, String proofNonce, String proofText) { + + LinkedIdCreateHttpsStep2Fragment frag = new LinkedIdCreateHttpsStep2Fragment(); + + Bundle args = new Bundle(); + args.putString(URI, uri); + args.putString(NONCE, proofNonce); + args.putString(TEXT, proofText); + frag.setArguments(args); + + return frag; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.linked_create_https_fragment_step2, container, false); + + mResourceUri = getArguments().getString(URI); + mResourceNonce = getArguments().getString(NONCE); + mResourceString = getArguments().getString(TEXT); + + 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_send).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + proofSend(); + } + }); + + view.findViewById(R.id.button_save).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + proofSave(); + } + }); + + view.findViewById(R.id.button_verify).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + proofVerify(); + } + }); + + mEditUri = (EditText) view.findViewById(R.id.linked_create_https_uri); + mEditUri.setText(mResourceUri); + + 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); + 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); + 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); + 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); + sendIntent.putExtra(Intent.EXTRA_TEXT, mResourceString); + sendIntent.setType("text/plain"); + startActivity(sendIntent); + } + + private void proofSave () { + String state = Environment.getExternalStorageState(); + if (!Environment.MEDIA_MOUNTED.equals(state)) { + Notify.showNotify(getActivity(), "External storage not available!", Style.ERROR); + return; + } + + String targetName = "pgpkey.txt"; + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { + File targetFile = new File(Constants.Path.APP_DIR, targetName); + FileHelper.saveFile(this, getString(R.string.title_decrypt_to_file), + getString(R.string.specify_file_to_decrypt_to), targetFile, REQUEST_CODE_OUTPUT); + } else { + FileHelper.saveDocument(this, "text/plain", targetName, REQUEST_CODE_OUTPUT); + } + } + + private void saveFile(Uri uri) { + try { + PrintWriter out = + new PrintWriter(getActivity().getContentResolver().openOutputStream(uri)); + out.print(mResourceString); + if (out.checkError()) { + Notify.showNotify(getActivity(), "Error writing file!", Style.ERROR); + } + } catch (FileNotFoundException e) { + Notify.showNotify(getActivity(), "File could not be opened for writing!", Style.ERROR); + e.printStackTrace(); + } + } + + public void proofVerify() { + setVerifyProgress(true, null); + + try { + final GenericHttpsResource resource = GenericHttpsResource.createNew(new URI(mResourceUri)); + + new AsyncTask() { + + @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(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + + } + + 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) { + // For saving a file + case REQUEST_CODE_OUTPUT: + if (data == null) { + return; + } + 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; + } + super.onActivityResult(requestCode, resultCode, data); + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep1Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep1Fragment.java new file mode 100644 index 000000000..25a4f6463 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep1Fragment.java @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui.linked; + +import android.os.AsyncTask; +import android.os.Bundle; +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 org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.linked.LinkedIdentity; +import org.sufficientlysecure.keychain.pgp.linked.resources.TwitterResource; +import org.sufficientlysecure.keychain.ui.util.Notify; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; + +public class LinkedIdCreateTwitterStep1Fragment extends Fragment { + + LinkedIdWizard mLinkedIdWizard; + + EditText mEditHandle; + + /** + * Creates new instance of this fragment + */ + public static LinkedIdCreateTwitterStep1Fragment newInstance() { + LinkedIdCreateTwitterStep1Fragment frag = new LinkedIdCreateTwitterStep1Fragment(); + + Bundle args = new Bundle(); + frag.setArguments(args); + + return frag; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + mLinkedIdWizard = (LinkedIdWizard) getActivity(); + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.linked_create_twitter_fragment_step1, container, false); + + view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + + final String handle = mEditHandle.getText().toString(); + + new AsyncTask() { + + @Override + protected Boolean doInBackground(Void... params) { + return true; // checkHandle(handle); + } + + @Override + protected void onPostExecute(Boolean result) { + super.onPostExecute(result); + + if (result == null) { + Notify.showNotify(getActivity(), "Connection error while checking username!", Notify.Style.ERROR); + return; + } + + if (!result) { + Notify.showNotify(getActivity(), "This handle does not exist on Twitter!", Notify.Style.ERROR); + return; + } + + String proofNonce = LinkedIdentity.generateNonce(); + String proofText = TwitterResource.generateText(getActivity(), + mLinkedIdWizard.mFingerprint, proofNonce); + + LinkedIdCreateTwitterStep2Fragment frag = + LinkedIdCreateTwitterStep2Fragment.newInstance(handle, proofNonce, proofText); + + mLinkedIdWizard.loadFragment(null, frag, LinkedIdWizard.FRAG_ACTION_TO_RIGHT); + } + }.execute(); + + } + }); + + 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); + } + }); + + mEditHandle = (EditText) view.findViewById(R.id.linked_create_twitter_handle); + mEditHandle.setText("Valodim"); + + return view; + } + + private static Boolean checkHandle(String handle) { + try { + HttpURLConnection nection = + (HttpURLConnection) new URL("https://twitter.com/" + handle).openConnection(); + nection.setRequestMethod("HEAD"); + return nection.getResponseCode() == 200; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep2Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep2Fragment.java new file mode 100644 index 000000000..c02a76669 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep2Fragment.java @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui.linked; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.text.Editable; +import android.text.InputFilter; +import android.text.TextWatcher; +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.R; + +public class LinkedIdCreateTwitterStep2Fragment extends Fragment { + + private static final int REQUEST_CODE_OUTPUT = 0x00007007; + + public static final String HANDLE = "uri", NONCE = "nonce", TEXT = "text"; + + LinkedIdWizard mLinkedIdWizard; + + EditText mEditTweetCustom, mEditTweetPreview; + ImageView mVerifyImage; + View mVerifyProgress; + TextView mVerifyStatus, mEditTweetTextLen; + + String mResourceHandle; + String mResourceNonce, mResourceString; + + /** + * Creates new instance of this fragment + */ + public static LinkedIdCreateTwitterStep2Fragment newInstance + (String handle, String proofNonce, String proofText) { + + LinkedIdCreateTwitterStep2Fragment frag = new LinkedIdCreateTwitterStep2Fragment(); + + Bundle args = new Bundle(); + args.putString(HANDLE, handle); + args.putString(NONCE, proofNonce); + args.putString(TEXT, proofText); + frag.setArguments(args); + + return frag; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.linked_create_twitter_fragment_step2, container, false); + + mResourceHandle = getArguments().getString(HANDLE); + mResourceNonce = getArguments().getString(NONCE); + mResourceString = getArguments().getString(TEXT); + + view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + + LinkedIdCreateTwitterStep3Fragment frag = + LinkedIdCreateTwitterStep3Fragment.newInstance(mResourceHandle, + mResourceNonce, mResourceString, + mEditTweetCustom.getText().toString()); + + mLinkedIdWizard.loadFragment(null, frag, LinkedIdWizard.FRAG_ACTION_TO_RIGHT); + } + }); + + 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); + + mEditTweetPreview = (EditText) view.findViewById(R.id.linked_create_twitter_preview); + mEditTweetPreview.setText(mResourceString); + + mEditTweetCustom = (EditText) view.findViewById(R.id.linked_create_twitter_custom); + mEditTweetCustom.setFilters(new InputFilter[] { + new InputFilter.LengthFilter(139 - mResourceString.length()) + }); + + mEditTweetTextLen = (TextView) view.findViewById(R.id.linked_create_twitter_textlen); + mEditTweetTextLen.setText(mResourceString.length() + "/140"); + + mEditTweetCustom.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { + } + + @Override + public void afterTextChanged(Editable editable) { + if (editable != null && editable.length() > 0) { + String str = editable + " " + mResourceString; + mEditTweetPreview.setText(str); + + mEditTweetTextLen.setText(str.length() + "/140"); + mEditTweetTextLen.setTextColor(getResources().getColor(str.length() == 140 + ? R.color.android_red_dark + : R.color.primary_dark_material_light)); + + + } else { + mEditTweetPreview.setText(mResourceString); + mEditTweetTextLen.setText(mResourceString.length() + "/140"); + } + } + }); + + return view; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + mLinkedIdWizard = (LinkedIdWizard) getActivity(); + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep3Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep3Fragment.java new file mode 100644 index 000000000..23e50d9dc --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateTwitterStep3Fragment.java @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui.linked; + +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.graphics.PorterDuff; +import android.os.Bundle; +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.R; +import org.sufficientlysecure.keychain.ui.util.Notify; + +import java.util.List; + +public class LinkedIdCreateTwitterStep3Fragment extends Fragment { + + public static final String HANDLE = "uri", NONCE = "nonce", TEXT = "text", CUSTOM = "custom"; + + LinkedIdWizard mLinkedIdWizard; + + EditText mEditTweetPreview; + ImageView mVerifyImage; + View mVerifyProgress; + TextView mVerifyStatus; + + String mResourceHandle, mCustom, mFullString; + String mResourceNonce, mResourceString; + + /** + * Creates new instance of this fragment + */ + public static LinkedIdCreateTwitterStep3Fragment newInstance + (String handle, String proofNonce, String proofText, String customText) { + + LinkedIdCreateTwitterStep3Fragment frag = new LinkedIdCreateTwitterStep3Fragment(); + + Bundle args = new Bundle(); + args.putString(HANDLE, handle); + args.putString(NONCE, proofNonce); + args.putString(TEXT, proofText); + args.putString(CUSTOM, customText); + frag.setArguments(args); + + return frag; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.linked_create_twitter_fragment_step3, container, false); + + mResourceHandle = getArguments().getString(HANDLE); + mResourceNonce = getArguments().getString(NONCE); + mResourceString = getArguments().getString(TEXT); + mCustom = getArguments().getString(CUSTOM); + + mFullString = mCustom.isEmpty() ? mResourceString : (mCustom + " " + mResourceString); + + mVerifyImage = (ImageView) view.findViewById(R.id.verify_image); + mVerifyProgress = view.findViewById(R.id.verify_progress); + mVerifyStatus = (TextView) view.findViewById(R.id.verify_status); + + mEditTweetPreview = (EditText) view.findViewById(R.id.linked_create_twitter_preview); + mEditTweetPreview.setText(mFullString); + + 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); + } + }); + + view.findViewById(R.id.button_send).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + proofSend(); + } + }); + + view.findViewById(R.id.button_share).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + proofShare(); + } + }); + + 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); + + + view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + + // AffirmationCreateHttpsStep2Fragment frag = + // AffirmationCreateHttpsStep2Fragment.newInstance(); + + // mAffirmationWizard.loadFragment(null, frag, AffirmationWizard.FRAG_ACTION_TO_RIGHT); + } + }); + + 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); + 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); + 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); + mVerifyImage.setColorFilter(getResources().getColor(R.color.android_red_dark), + PorterDuff.Mode.SRC_IN); + } + } + + public void proofVerify() { + setVerifyProgress(true, null); + + /* + try { + final TwitterResource resource = TwitterResource.createNew(new URI(mResourceHandle)); + + new AsyncTask() { + + @Override + protected LinkedVerifyResult doInBackground(Void... params) { + return resource.verify(mAffirmationWizard.mFingerprint, mResourceNonce); + } + + @Override + protected void onPostExecute(LinkedVerifyResult result) { + super.onPostExecute(result); + if (result.success()) { + setVerifyProgress(false, true); + } else { + setVerifyProgress(false, false); + // on error, show error message + result.createNotify(getActivity()).show(); + } + } + }.execute(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + */ + + } + + private void proofShare() { + Intent sendIntent = new Intent(); + sendIntent.setAction(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_TEXT, mFullString); + sendIntent.setType("text/plain"); + startActivity(sendIntent); + } + + private void proofSend() { + + Intent tweetIntent = new Intent(Intent.ACTION_SEND); + tweetIntent.putExtra(Intent.EXTRA_TEXT, mFullString); + tweetIntent.setType("text/plain"); + + PackageManager packManager = getActivity().getPackageManager(); + List resolvedInfoList = packManager.queryIntentActivities(tweetIntent, + PackageManager.MATCH_DEFAULT_ONLY); + + boolean resolved = false; + for(ResolveInfo resolveInfo : resolvedInfoList){ + if(resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) { + tweetIntent.setClassName( + resolveInfo.activityInfo.packageName, + resolveInfo.activityInfo.name ); + resolved = true; + break; + } + } + + if (resolved) { + startActivity(tweetIntent); + } else { + Notify.showNotify(getActivity(), + "Twitter app is not installed, please use the send intent!", + Notify.Style.ERROR); + } + + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdSelectFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdSelectFragment.java new file mode 100644 index 000000000..abe7dbaf1 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdSelectFragment.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui.linked; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import org.sufficientlysecure.keychain.R; + +public class LinkedIdSelectFragment extends Fragment { + + LinkedIdWizard mLinkedIdWizard; + + /** + * Creates new instance of this fragment + */ + public static LinkedIdSelectFragment newInstance() { + LinkedIdSelectFragment frag = new LinkedIdSelectFragment(); + + Bundle args = new Bundle(); + frag.setArguments(args); + + return frag; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.linked_select_fragment, container, false); + + view.findViewById(R.id.linked_create_https_button) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + LinkedIdCreateHttpsStep1Fragment frag = + LinkedIdCreateHttpsStep1Fragment.newInstance(); + + mLinkedIdWizard.loadFragment(null, frag, LinkedIdWizard.FRAG_ACTION_TO_RIGHT); + } + }); + + view.findViewById(R.id.linked_create_dns_button) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + LinkedIdCreateDnsStep1Fragment frag = + LinkedIdCreateDnsStep1Fragment.newInstance(); + + mLinkedIdWizard.loadFragment(null, frag, LinkedIdWizard.FRAG_ACTION_TO_RIGHT); + } + }); + + view.findViewById(R.id.linked_create_twitter_button) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + LinkedIdCreateTwitterStep1Fragment frag = + LinkedIdCreateTwitterStep1Fragment.newInstance(); + + mLinkedIdWizard.loadFragment(null, frag, LinkedIdWizard.FRAG_ACTION_TO_RIGHT); + } + }); + + return view; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + mLinkedIdWizard = (LinkedIdWizard) getActivity(); + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java new file mode 100644 index 000000000..b8f3329c1 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui.linked; + +import android.net.Uri; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.ActionBarActivity; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; +import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.util.Log; + +public class LinkedIdWizard extends ActionBarActivity { + + public static final int FRAG_ACTION_START = 0; + public static final int FRAG_ACTION_TO_RIGHT = 1; + public static final int FRAG_ACTION_TO_LEFT = 2; + + long mMasterKeyId; + byte[] mFingerprint; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.create_key_activity); + + try { + Uri uri = getIntent().getData(); + CachedPublicKeyRing ring = new ProviderHelper(this).getCachedPublicKeyRing(uri); + mMasterKeyId = ring.extractOrGetMasterKeyId(); + mFingerprint = ring.getFingerprint(); + } catch (PgpKeyNotFoundException e) { + Log.e(Constants.TAG, "Invalid uri given, key does not exist!"); + finish(); + return; + } + + // pass extras into fragment + LinkedIdSelectFragment frag = LinkedIdSelectFragment.newInstance(); + loadFragment(null, frag, FRAG_ACTION_START); + } + + public void loadFragment(Bundle savedInstanceState, Fragment fragment, int action) { + // However, if we're being restored from a previous state, + // then we don't need to do anything and should return or else + // we could end up with overlapping fragments. + if (savedInstanceState != null) { + return; + } + + // Add the fragment to the 'fragment_container' FrameLayout + // NOTE: We use commitAllowingStateLoss() to prevent weird crashes! + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + + switch (action) { + case FRAG_ACTION_START: + transaction.setCustomAnimations(0, 0); + transaction.replace(R.id.create_key_fragment_container, fragment) + .commitAllowingStateLoss(); + break; + case FRAG_ACTION_TO_LEFT: + getSupportFragmentManager().popBackStackImmediate(); + break; + case FRAG_ACTION_TO_RIGHT: + transaction.setCustomAnimations(R.anim.frag_slide_in_from_right, R.anim.frag_slide_out_to_left, + R.anim.frag_slide_in_from_left, R.anim.frag_slide_out_to_right); + transaction.addToBackStack(null); + transaction.replace(R.id.create_key_fragment_container, fragment) + .commitAllowingStateLoss(); + break; + + } + // do it immediately! + getSupportFragmentManager().executePendingTransactions(); + } + +} -- cgit v1.2.3