successfully certify linked ids

This commit is contained in:
Vincent Breitmoser 2015-03-08 04:42:19 +01:00
parent b57bcefe08
commit 99eb8725e9
5 changed files with 80 additions and 20 deletions

View File

@ -41,6 +41,7 @@ import android.os.Messenger;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.provider.Settings; import android.provider.Settings;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.LoaderManager; import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader; import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader; import android.support.v4.content.Loader;
@ -999,15 +1000,21 @@ public class ViewKeyActivity extends BaseActivity implements
private void startFragment(boolean isSecret, byte[] fingerprint) { private void startFragment(boolean isSecret, byte[] fingerprint) {
// Create an instance of the fragment // Create an instance of the fragment
ViewKeyFragment frag = ViewKeyFragment.newInstance(mDataUri, isSecret, fingerprint); final ViewKeyFragment frag = ViewKeyFragment.newInstance(mDataUri, isSecret, fingerprint);
// Add the fragment to the 'fragment_container' FrameLayout new Handler().post(new Runnable() {
// NOTE: We use commitAllowingStateLoss() to prevent weird crashes! @Override
getSupportFragmentManager().beginTransaction() public void run() {
.replace(R.id.view_key_fragment, frag, "main")
.commitAllowingStateLoss(); FragmentManager manager = getSupportFragmentManager();
// do it immediately! manager.popBackStack("linked_id", FragmentManager.POP_BACK_STACK_INCLUSIVE);
getSupportFragmentManager().executePendingTransactions(); // Add the fragment to the 'fragment_container' FrameLayout
// NOTE: We use commitAllowingStateLoss() to prevent weird crashes!
manager.beginTransaction()
.replace(R.id.view_key_fragment, frag, "main")
.commit();
}
});
} }
} }

View File

@ -148,7 +148,7 @@ public class ViewKeyFragment extends LoaderFragment implements
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
.replace(R.id.view_key_fragment, frag) .replace(R.id.view_key_fragment, frag)
.addSharedElement(mLinkedIdsCard, "card_linked_ids") .addSharedElement(mLinkedIdsCard, "card_linked_ids")
.addToBackStack(null) .addToBackStack("linked_id")
.commit(); .commit();
} }

View File

@ -1,6 +1,7 @@
package org.sufficientlysecure.keychain.ui.linked; package org.sufficientlysecure.keychain.ui.linked;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
@ -22,9 +23,11 @@ import android.widget.TextView;
import android.widget.ViewAnimator; import android.widget.ViewAnimator;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.operations.results.CertifyResult;
import org.sufficientlysecure.keychain.operations.results.LinkedVerifyResult; import org.sufficientlysecure.keychain.operations.results.LinkedVerifyResult;
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource; import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
import org.sufficientlysecure.keychain.pgp.linked.LinkedIdentity; import org.sufficientlysecure.keychain.pgp.linked.LinkedIdentity;
import org.sufficientlysecure.keychain.pgp.linked.LinkedResource; import org.sufficientlysecure.keychain.pgp.linked.LinkedResource;
@ -34,21 +37,25 @@ import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
import org.sufficientlysecure.keychain.ui.adapter.LinkedIdsAdapter.ViewHolder; import org.sufficientlysecure.keychain.ui.adapter.LinkedIdsAdapter.ViewHolder;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner; import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.Preferences;
public class LinkedIdViewFragment extends Fragment { public class LinkedIdViewFragment extends Fragment {
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
private static final String ARG_ENCODED_LID = "encoded_lid"; private static final String ARG_ENCODED_LID = "encoded_lid";
private static final String ARG_VERIFIED = "verified"; private static final String ARG_VERIFIED = "verified";
private static final String ARG_FINGERPRINT = "fingerprint"; private static final String ARG_FINGERPRINT = "fingerprint";
private static final String ARG_MASTER_KEY_ID = "fingerprint";
private RawLinkedIdentity mLinkedId; private RawLinkedIdentity mLinkedId;
private LinkedCookieResource mLinkedResource; private LinkedCookieResource mLinkedResource;
@ -195,7 +202,7 @@ public class LinkedIdViewFragment extends Fragment {
button_confirm.setOnClickListener(new OnClickListener() { button_confirm.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
certifyResource(); initiateCertifying();
} }
}); });
@ -291,15 +298,62 @@ public class LinkedIdViewFragment extends Fragment {
} }
private void certifyResource() { private void initiateCertifying() {
// get the user's passphrase for this key (if required)
String passphrase;
long certifyKeyId = vKeySpinner.getSelectedItemId();
try {
passphrase = PassphraseCacheService.getCachedPassphrase(
getActivity(), certifyKeyId, certifyKeyId);
} catch (PassphraseCacheService.KeyNotFoundException e) {
Log.e(Constants.TAG, "Key not found!", e);
getActivity().finish();
return;
}
if (passphrase == null) {
Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class);
intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, certifyKeyId);
startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
// bail out; need to wait until the user has entered the passphrase before trying again
} else {
certifyResource(certifyKeyId, "");
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_PASSPHRASE: {
if (resultCode == Activity.RESULT_OK && data != null) {
String passphrase = data.getStringExtra(
PassphraseDialogActivity.MESSAGE_DATA_PASSPHRASE);
long certifyKeyId = data.getLongExtra(PassphraseDialogActivity.EXTRA_KEY_ID, 0L);
if (certifyKeyId == 0L) {
throw new AssertionError("key id must not be 0");
}
certifyResource(certifyKeyId, passphrase);
}
return;
}
default: {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
private void certifyResource(long certifyKeyId, String passphrase) {
Bundle data = new Bundle(); Bundle data = new Bundle();
{ {
CertifyAction action = new CertifyAction();
long masterKeyId = KeyFormattingUtils.convertFingerprintToKeyId(mFingerprint);
CertifyAction action = new CertifyAction(masterKeyId, null,
Arrays.asList(mLinkedId.toUserAttribute()));
// fill values for this action // fill values for this action
CertifyActionsParcel parcel = new CertifyActionsParcel(vKeySpinner.getSelectedKeyId()); CertifyActionsParcel parcel = new CertifyActionsParcel(certifyKeyId);
parcel.mCertifyActions.addAll(certifyActions); parcel.mCertifyActions.addAll(Arrays.asList(action));
data.putParcelable(KeychainIntentService.CERTIFY_PARCEL, parcel); data.putParcelable(KeychainIntentService.CERTIFY_PARCEL, parcel);
/* if (mUploadKeyCheckbox.isChecked()) { /* if (mUploadKeyCheckbox.isChecked()) {
@ -315,7 +369,7 @@ public class LinkedIdViewFragment extends Fragment {
// Message is received after signing is done in KeychainIntentService // Message is received after signing is done in KeychainIntentService
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(), KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(),
getString(R.string.progress_certifying), ProgressDialog.STYLE_SPINNER, true) { getString(R.string.progress_certifying), ProgressDialog.STYLE_SPINNER, false) {
public void handleMessage(Message message) { public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first // handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message); super.handleMessage(message);
@ -324,10 +378,7 @@ public class LinkedIdViewFragment extends Fragment {
Bundle data = message.getData(); Bundle data = message.getData();
CertifyResult result = data.getParcelable(CertifyResult.EXTRA_RESULT); CertifyResult result = data.getParcelable(CertifyResult.EXTRA_RESULT);
Intent intent = new Intent(); result.createNotify(getActivity()).show();
intent.putExtra(CertifyResult.EXTRA_RESULT, result);
getActivity().setResult(Activity.RESULT_OK, intent);
getActivity().finish();
} }
} }
}; };

View File

@ -269,6 +269,7 @@ public abstract class KeySpinner extends TintSpinner implements LoaderManager.Lo
} }
return view; return view;
} }
} }
boolean setStatus(Context context, Cursor cursor, ImageView statusView) { boolean setStatus(Context context, Cursor cursor, ImageView statusView) {

View File

@ -36,6 +36,7 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:animateLayoutChanges="true"
android:id="@+id/linked_id_certs"> android:id="@+id/linked_id_certs">
</LinearLayout> </LinearLayout>