Add create key fragments for YubiKey PINs
This commit is contained in:
parent
d41c5bbbc1
commit
362c83abe7
|
@ -29,7 +29,6 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKey;
|
|||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.service.PromoteKeyringParcel;
|
||||
|
@ -37,7 +36,6 @@ import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
|||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/** An operation which promotes a public key ring to a secret one.
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.LogTyp
|
|||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation;
|
||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
|
||||
|
|
|
@ -42,7 +42,9 @@ public class CreateKeyActivity extends BaseNfcActivity {
|
|||
public static final String EXTRA_FIRST_TIME = "first_time";
|
||||
public static final String EXTRA_ADDITIONAL_EMAILS = "additional_emails";
|
||||
public static final String EXTRA_PASSPHRASE = "passphrase";
|
||||
public static final String EXTRA_USE_SMART_CARD_SETTINGS = "use_smart_card_settings";
|
||||
public static final String EXTRA_CREATE_YUBI_KEY = "create_yubi_key";
|
||||
public static final String EXTRA_YUBI_KEY_PIN = "yubi_key_pin";
|
||||
public static final String EXTRA_YUBI_KEY_ADMIN_PIN = "yubi_key_admin_pin";
|
||||
|
||||
public static final String EXTRA_NFC_USER_ID = "nfc_user_id";
|
||||
public static final String EXTRA_NFC_AID = "nfc_aid";
|
||||
|
@ -55,7 +57,9 @@ public class CreateKeyActivity extends BaseNfcActivity {
|
|||
ArrayList<String> mAdditionalEmails;
|
||||
Passphrase mPassphrase;
|
||||
boolean mFirstTime;
|
||||
boolean mUseSmartCardSettings;
|
||||
boolean mCreateYubiKey;
|
||||
String mYubiKeyPin;
|
||||
String mYubiKeyAdminPin;
|
||||
|
||||
Fragment mCurrentFragment;
|
||||
|
||||
|
@ -88,7 +92,9 @@ public class CreateKeyActivity extends BaseNfcActivity {
|
|||
mAdditionalEmails = savedInstanceState.getStringArrayList(EXTRA_ADDITIONAL_EMAILS);
|
||||
mPassphrase = savedInstanceState.getParcelable(EXTRA_PASSPHRASE);
|
||||
mFirstTime = savedInstanceState.getBoolean(EXTRA_FIRST_TIME);
|
||||
mUseSmartCardSettings = savedInstanceState.getBoolean(EXTRA_USE_SMART_CARD_SETTINGS);
|
||||
mCreateYubiKey = savedInstanceState.getBoolean(EXTRA_CREATE_YUBI_KEY);
|
||||
mYubiKeyPin = savedInstanceState.getString(EXTRA_YUBI_KEY_PIN);
|
||||
mYubiKeyAdminPin = savedInstanceState.getString(EXTRA_YUBI_KEY_ADMIN_PIN);
|
||||
|
||||
mCurrentFragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
|
||||
} else {
|
||||
|
@ -98,7 +104,7 @@ public class CreateKeyActivity extends BaseNfcActivity {
|
|||
mName = intent.getStringExtra(EXTRA_NAME);
|
||||
mEmail = intent.getStringExtra(EXTRA_EMAIL);
|
||||
mFirstTime = intent.getBooleanExtra(EXTRA_FIRST_TIME, false);
|
||||
mUseSmartCardSettings = intent.getBooleanExtra(EXTRA_USE_SMART_CARD_SETTINGS, false);
|
||||
mCreateYubiKey = intent.getBooleanExtra(EXTRA_CREATE_YUBI_KEY, false);
|
||||
|
||||
if (intent.hasExtra(EXTRA_NFC_FINGERPRINTS)) {
|
||||
byte[] nfcFingerprints = intent.getByteArrayExtra(EXTRA_NFC_FINGERPRINTS);
|
||||
|
@ -106,13 +112,13 @@ public class CreateKeyActivity extends BaseNfcActivity {
|
|||
byte[] nfcAid = intent.getByteArrayExtra(EXTRA_NFC_AID);
|
||||
|
||||
if (containsKeys(nfcFingerprints)) {
|
||||
Fragment frag = CreateKeyYubiKeyImportFragment.newInstance(
|
||||
Fragment frag = CreateYubiKeyImportFragment.newInstance(
|
||||
nfcFingerprints, nfcAid, nfcUserId);
|
||||
loadFragment(frag, FragAction.START);
|
||||
|
||||
setTitle(R.string.title_import_keys);
|
||||
} else {
|
||||
Fragment frag = CreateKeyYubiKeyBlankFragment.newInstance();
|
||||
Fragment frag = CreateYubiKeyBlankFragment.newInstance();
|
||||
loadFragment(frag, FragAction.START);
|
||||
setTitle(R.string.title_manage_my_keys);
|
||||
}
|
||||
|
@ -161,12 +167,12 @@ public class CreateKeyActivity extends BaseNfcActivity {
|
|||
finish();
|
||||
|
||||
} catch (PgpKeyNotFoundException e) {
|
||||
Fragment frag = CreateKeyYubiKeyImportFragment.newInstance(
|
||||
Fragment frag = CreateYubiKeyImportFragment.newInstance(
|
||||
scannedFingerprints, nfcAid, userId);
|
||||
loadFragment(frag, FragAction.TO_RIGHT);
|
||||
}
|
||||
} else {
|
||||
Fragment frag = CreateKeyYubiKeyBlankFragment.newInstance();
|
||||
Fragment frag = CreateYubiKeyBlankFragment.newInstance();
|
||||
loadFragment(frag, FragAction.TO_RIGHT);
|
||||
}
|
||||
|
||||
|
@ -193,7 +199,9 @@ public class CreateKeyActivity extends BaseNfcActivity {
|
|||
outState.putStringArrayList(EXTRA_ADDITIONAL_EMAILS, mAdditionalEmails);
|
||||
outState.putParcelable(EXTRA_PASSPHRASE, mPassphrase);
|
||||
outState.putBoolean(EXTRA_FIRST_TIME, mFirstTime);
|
||||
outState.putBoolean(EXTRA_USE_SMART_CARD_SETTINGS, mUseSmartCardSettings);
|
||||
outState.putBoolean(EXTRA_CREATE_YUBI_KEY, mCreateYubiKey);
|
||||
outState.putString(EXTRA_YUBI_KEY_PIN, mYubiKeyPin);
|
||||
outState.putString(EXTRA_YUBI_KEY_ADMIN_PIN, mYubiKeyAdminPin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
@ -29,6 +30,7 @@ import android.support.v7.widget.RecyclerView;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
|
@ -37,9 +39,9 @@ import android.widget.TextView;
|
|||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.AddEmailDialogFragment;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.widget.EmailEditText;
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -201,7 +203,7 @@ public class CreateKeyEmailFragment extends Fragment {
|
|||
Handler returnHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
if (message.what == SetPassphraseDialogFragment.MESSAGE_OKAY) {
|
||||
if (message.what == AddEmailDialogFragment.MESSAGE_OKAY) {
|
||||
Bundle data = message.getData();
|
||||
|
||||
String email = data.getString(AddEmailDialogFragment.MESSAGE_DATA_EMAIL);
|
||||
|
@ -232,11 +234,38 @@ public class CreateKeyEmailFragment extends Fragment {
|
|||
mCreateKeyActivity.mEmail = mEmailEdit.getText().toString();
|
||||
mCreateKeyActivity.mAdditionalEmails = getAdditionalEmails();
|
||||
|
||||
CreateKeyPassphraseFragment frag = CreateKeyPassphraseFragment.newInstance();
|
||||
mCreateKeyActivity.loadFragment(frag, FragAction.TO_RIGHT);
|
||||
CreateKeyActivity createKeyActivity = ((CreateKeyActivity) getActivity());
|
||||
|
||||
if (createKeyActivity.mCreateYubiKey) {
|
||||
hideKeyboard();
|
||||
|
||||
// set empty passphrase
|
||||
createKeyActivity.mPassphrase = new Passphrase();
|
||||
|
||||
CreateYubiKeyPinFragment frag = CreateYubiKeyPinFragment.newInstance();
|
||||
mCreateKeyActivity.loadFragment(frag, FragAction.TO_RIGHT);
|
||||
} else {
|
||||
CreateKeyPassphraseFragment frag = CreateKeyPassphraseFragment.newInstance();
|
||||
mCreateKeyActivity.loadFragment(frag, FragAction.TO_RIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void hideKeyboard() {
|
||||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
InputMethodManager inputManager = (InputMethodManager) getActivity()
|
||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
// check if no view has focus
|
||||
View v = getActivity().getCurrentFocus();
|
||||
if (v == null)
|
||||
return;
|
||||
|
||||
inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
private ArrayList<String> getAdditionalEmails() {
|
||||
ArrayList<String> emails = new ArrayList<>();
|
||||
for (EmailAdapter.ViewModel holder : mAdditionalEmailModels) {
|
||||
|
|
|
@ -178,7 +178,7 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||
if (mSaveKeyringParcel == null) {
|
||||
mSaveKeyringParcel = new SaveKeyringParcel();
|
||||
|
||||
if (createKeyActivity.mUseSmartCardSettings) {
|
||||
if (createKeyActivity.mCreateYubiKey) {
|
||||
mSaveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Algorithm.RSA,
|
||||
2048, null, KeyFlags.SIGN_DATA | KeyFlags.CERTIFY_OTHER, 0L));
|
||||
mSaveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Algorithm.RSA,
|
||||
|
@ -228,7 +228,7 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||
@Override
|
||||
public void onCryptoOperationSuccess(EditKeyResult result) {
|
||||
|
||||
if (createKeyActivity.mUseSmartCardSettings) {
|
||||
if (createKeyActivity.mCreateYubiKey) {
|
||||
moveToCard(result);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class CreateKeyStartFragment extends Fragment {
|
|||
mYubiKey.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CreateKeyYubiKeyWaitFragment frag = new CreateKeyYubiKeyWaitFragment();
|
||||
CreateYubiKeyWaitFragment frag = new CreateYubiKeyWaitFragment();
|
||||
mCreateKeyActivity.loadFragment(frag, FragAction.TO_RIGHT);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -27,7 +27,7 @@ import android.view.ViewGroup;
|
|||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
||||
|
||||
public class CreateKeyYubiKeyBlankFragment extends Fragment {
|
||||
public class CreateYubiKeyBlankFragment extends Fragment {
|
||||
|
||||
CreateKeyActivity mCreateKeyActivity;
|
||||
View mBackButton;
|
||||
|
@ -36,8 +36,8 @@ public class CreateKeyYubiKeyBlankFragment extends Fragment {
|
|||
/**
|
||||
* Creates new instance of this fragment
|
||||
*/
|
||||
public static CreateKeyYubiKeyBlankFragment newInstance() {
|
||||
CreateKeyYubiKeyBlankFragment frag = new CreateKeyYubiKeyBlankFragment();
|
||||
public static CreateYubiKeyBlankFragment newInstance() {
|
||||
CreateYubiKeyBlankFragment frag = new CreateYubiKeyBlankFragment();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class CreateKeyYubiKeyBlankFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void nextClicked() {
|
||||
mCreateKeyActivity.mUseSmartCardSettings = true;
|
||||
mCreateKeyActivity.mCreateYubiKey = true;
|
||||
|
||||
CreateKeyNameFragment frag = CreateKeyNameFragment.newInstance();
|
||||
mCreateKeyActivity.loadFragment(frag, FragAction.TO_RIGHT);
|
|
@ -44,7 +44,7 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
|||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
|
||||
|
||||
public class CreateKeyYubiKeyImportFragment
|
||||
public class CreateYubiKeyImportFragment
|
||||
extends CryptoOperationFragment<ImportKeyringParcel, ImportKeyResult>
|
||||
implements NfcListenerFragment {
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class CreateKeyYubiKeyImportFragment
|
|||
|
||||
public static Fragment newInstance(byte[] scannedFingerprints, byte[] nfcAid, String userId) {
|
||||
|
||||
CreateKeyYubiKeyImportFragment frag = new CreateKeyYubiKeyImportFragment();
|
||||
CreateYubiKeyImportFragment frag = new CreateYubiKeyImportFragment();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putByteArray(ARG_FINGERPRINT, scannedFingerprints);
|
|
@ -28,7 +28,7 @@ import org.sufficientlysecure.keychain.R;
|
|||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
||||
|
||||
|
||||
public class CreateKeyYubiKeyWaitFragment extends Fragment {
|
||||
public class CreateYubiKeyWaitFragment extends Fragment {
|
||||
|
||||
CreateKeyActivity mCreateKeyActivity;
|
||||
View mBackButton;
|
|
@ -654,6 +654,13 @@
|
|||
<string name="create_key_add_email_text">"Additional email addresses are also associated to this key and can be used for secure communication."</string>
|
||||
<string name="create_key_email_already_exists_text">"Email address has already been added"</string>
|
||||
<string name="create_key_email_invalid_email">"Email address format is invalid"</string>
|
||||
<string name="create_key_yubi_key_pin_text">"Please remember these PINs. They are required to use your YubiKey later. If possible write down the Admin PIN and store it in a safe place."</string>
|
||||
<string name="create_key_yubi_key_pin">"PIN"</string>
|
||||
<string name="create_key_yubi_key_admin_pin">"Admin PIN"</string>
|
||||
<string name="create_key_yubi_key_pin_repeat_text">"Please enter the PIN and Admin PIN to proceed."</string>
|
||||
<string name="create_key_yubi_key_pin_repeat">"Repeat PIN"</string>
|
||||
<string name="create_key_yubi_key_admin_pin_repeat">"Repeat Admin PIN"</string>
|
||||
<string name="create_key_yubi_key_pin_not_correct">"PIN is not correct!"</string>
|
||||
|
||||
<!-- View key -->
|
||||
<string name="view_key_revoked">"Revoked: Key must not be used anymore!"</string>
|
||||
|
|
Loading…
Reference in a new issue