split up wait/action yubikey fragments
This commit is contained in:
@@ -74,7 +74,7 @@ public class PromoteKeyOperation extends BaseOperation {
|
||||
mProviderHelper.getCanonicalizedPublicKeyRing(masterKeyId);
|
||||
|
||||
// create divert-to-card secret key from public key
|
||||
promotedRing = pubRing.createDummySecretRing();
|
||||
promotedRing = pubRing.createDummySecretRing(true);
|
||||
|
||||
} catch (PgpKeyNotFoundException e) {
|
||||
log.add(LogType.MSG_PR_ERROR_KEY_NOT_FOUND, 2);
|
||||
|
||||
@@ -97,10 +97,12 @@ public class CanonicalizedPublicKeyRing extends CanonicalizedKeyRing {
|
||||
}
|
||||
|
||||
/** Create a dummy secret ring from this key */
|
||||
public UncachedKeyRing createDummySecretRing () {
|
||||
public UncachedKeyRing createDummySecretRing (boolean divertToCard) {
|
||||
|
||||
PGPSecretKeyRing secRing = PGPSecretKeyRing.constructDummyFromPublic(getRing(),
|
||||
S2K.GNU_PROTECTION_MODE_NO_PRIVATE_KEY);
|
||||
divertToCard
|
||||
? S2K.GNU_PROTECTION_MODE_DIVERT_TO_CARD
|
||||
: S2K.GNU_PROTECTION_MODE_NO_PRIVATE_KEY);
|
||||
return new UncachedKeyRing(secRing);
|
||||
|
||||
}
|
||||
|
||||
@@ -84,7 +84,13 @@ public class CreateKeyActivity extends BaseNfcActivity {
|
||||
protected void onNfcPerform() throws IOException {
|
||||
if (mCurrentFragment instanceof NfcListenerFragment) {
|
||||
((NfcListenerFragment) mCurrentFragment).onNfcPerform();
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] scannedFingerprint = nfcGetFingerprint(0);
|
||||
Fragment frag = CreateKeyYubiFragment.createInstance(scannedFingerprint);
|
||||
loadFragment(frag, FragAction.TO_RIGHT);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -98,7 +98,7 @@ public class CreateKeyStartFragment extends Fragment {
|
||||
mYubiKey.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CreateKeyYubiFragment frag = new CreateKeyYubiFragment();
|
||||
CreateKeyYubiWaitFragment frag = new CreateKeyYubiWaitFragment();
|
||||
mCreateKeyActivity.loadFragment(frag, FragAction.TO_RIGHT);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -23,8 +23,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
@@ -38,11 +36,9 @@ import android.support.v4.content.Loader;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ViewAnimator;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||
@@ -51,57 +47,59 @@ import org.sufficientlysecure.keychain.operations.results.PromoteKeyResult;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentService.IOType;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.NfcListenerFragment;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
import org.sufficientlysecure.keychain.ui.widget.NameEditText;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
|
||||
|
||||
public class CreateKeyYubiFragment extends Fragment implements NfcListenerFragment,
|
||||
LoaderManager.LoaderCallbacks<Cursor> {
|
||||
public class CreateKeyYubiFragment extends Fragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
|
||||
private static final String ARG_FINGERPRINT = "fingerprint";
|
||||
|
||||
CreateKeyActivity mCreateKeyActivity;
|
||||
NameEditText mNameEdit;
|
||||
View mBackButton;
|
||||
View mNextButton;
|
||||
private TextView mUnknownFingerprint;
|
||||
|
||||
public static final String ARGS_MASTER_KEY_ID = "master_key_id";
|
||||
private byte[] mScannedFingerprint;
|
||||
private long mScannedMasterKeyId;
|
||||
|
||||
private ViewAnimator mAnimator;
|
||||
private TextView mUnknownFingerprint;
|
||||
private TextView mFingerprint;
|
||||
private TextView mUserId;
|
||||
|
||||
private YubiImportState mState = YubiImportState.SCAN;
|
||||
private YubiImportState mState;
|
||||
|
||||
public static Fragment createInstance(byte[] scannedFingerprint) {
|
||||
Bundle args = new Bundle();
|
||||
args.putByteArray(ARG_FINGERPRINT, scannedFingerprint);
|
||||
|
||||
CreateKeyYubiFragment frag = new CreateKeyYubiFragment();
|
||||
frag.setArguments(args);
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mScannedFingerprint = getArguments().getByteArray(ARG_FINGERPRINT);
|
||||
mScannedMasterKeyId = getKeyIdFromFingerprint(mScannedFingerprint);
|
||||
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
enum YubiImportState {
|
||||
SCAN, // waiting for scan
|
||||
UNKNOWN, // scanned unknown key (ready to import)
|
||||
BAD_FINGERPRINT, // scanned key, bad fingerprint
|
||||
IMPORTED, // imported key (ready to promote)
|
||||
}
|
||||
|
||||
private static boolean isEditTextNotEmpty(Context context, EditText editText) {
|
||||
boolean output = true;
|
||||
if (editText.getText().length() == 0) {
|
||||
editText.setError(context.getString(R.string.create_key_empty));
|
||||
editText.requestFocus();
|
||||
output = false;
|
||||
} else {
|
||||
editText.setError(null);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.create_yubikey_fragment, container, false);
|
||||
@@ -113,8 +111,8 @@ public class CreateKeyYubiFragment extends Fragment implements NfcListenerFragme
|
||||
mFingerprint = (TextView) view.findViewById(R.id.create_yubikey_fingerprint);
|
||||
mUserId = (TextView) view.findViewById(R.id.create_yubikey_user_id);
|
||||
|
||||
mBackButton = view.findViewById(R.id.create_key_back_button);
|
||||
mNextButton = view.findViewById(R.id.create_key_next_button);
|
||||
View mBackButton = view.findViewById(R.id.create_key_back_button);
|
||||
View mNextButton = view.findViewById(R.id.create_key_next_button);
|
||||
|
||||
mBackButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -138,16 +136,6 @@ public class CreateKeyYubiFragment extends Fragment implements NfcListenerFragme
|
||||
mCreateKeyActivity = (CreateKeyActivity) getActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNfcPerform() throws IOException {
|
||||
|
||||
mScannedFingerprint = mCreateKeyActivity.nfcGetFingerprint(0);
|
||||
mScannedMasterKeyId = getKeyIdFromFingerprint(mScannedFingerprint);
|
||||
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
|
||||
}
|
||||
|
||||
// These are the rows that we will retrieve.
|
||||
static final String[] UNIFIED_PROJECTION = new String[]{
|
||||
KeychainContract.KeyRings._ID,
|
||||
@@ -185,35 +173,26 @@ public class CreateKeyYubiFragment extends Fragment implements NfcListenerFragme
|
||||
return;
|
||||
}
|
||||
|
||||
showKey(data);
|
||||
String userId = data.getString(INDEX_USER_ID);
|
||||
boolean hasSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0;
|
||||
|
||||
String fp = KeyFormattingUtils.convertFingerprintToHex(mScannedFingerprint);
|
||||
mFingerprint.setText(KeyFormattingUtils.colorizeFingerprint(fp));
|
||||
|
||||
mUserId.setText(userId);
|
||||
|
||||
mAnimator.setDisplayedChild(2);
|
||||
mState = YubiImportState.IMPORTED;
|
||||
|
||||
} else {
|
||||
showUnknownKey();
|
||||
String fp = KeyFormattingUtils.convertFingerprintToHex(mScannedFingerprint);
|
||||
mUnknownFingerprint.setText(KeyFormattingUtils.colorizeFingerprint(fp));
|
||||
|
||||
mAnimator.setDisplayedChild(1);
|
||||
mState = YubiImportState.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public void showUnknownKey() {
|
||||
String fp = KeyFormattingUtils.convertFingerprintToHex(mScannedFingerprint);
|
||||
mUnknownFingerprint.setText(KeyFormattingUtils.colorizeFingerprint(fp));
|
||||
|
||||
mAnimator.setDisplayedChild(1);
|
||||
mState = YubiImportState.UNKNOWN;
|
||||
}
|
||||
|
||||
public void showKey(Cursor data) {
|
||||
String userId = data.getString(INDEX_USER_ID);
|
||||
boolean hasSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0;
|
||||
|
||||
String fp = KeyFormattingUtils.convertFingerprintToHex(mScannedFingerprint);
|
||||
mFingerprint.setText(KeyFormattingUtils.colorizeFingerprint(fp));
|
||||
|
||||
mUserId.setText(userId);
|
||||
|
||||
mAnimator.setDisplayedChild(2);
|
||||
mState = YubiImportState.IMPORTED;
|
||||
}
|
||||
|
||||
|
||||
private void nextClicked() {
|
||||
|
||||
switch (mState) {
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ViewAnimator;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.PromoteKeyResult;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.NfcListenerFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
import org.sufficientlysecure.keychain.ui.widget.NameEditText;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
|
||||
|
||||
public class CreateKeyYubiWaitFragment extends Fragment {
|
||||
|
||||
CreateKeyActivity mCreateKeyActivity;
|
||||
View mBackButton;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.create_yubikey_wait_fragment, container, false);
|
||||
|
||||
mBackButton = view.findViewById(R.id.create_key_back_button);
|
||||
|
||||
mBackButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mCreateKeyActivity.loadFragment(null, FragAction.TO_LEFT);
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
mCreateKeyActivity = (CreateKeyActivity) getActivity();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user