token-import: introduce parcelable SecurityTokenInfo
This commit is contained in:
@@ -956,6 +956,25 @@ public class SecurityTokenHelper {
|
|||||||
return mOpenPgpCapabilities;
|
return mOpenPgpCapabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SecurityTokenInfo getTokenInfo() throws IOException {
|
||||||
|
byte[] fingerprints = getFingerprints();
|
||||||
|
|
||||||
|
byte[] fpSign = new byte[20];
|
||||||
|
byte[] fpDecrypt = new byte[20];
|
||||||
|
byte[] fpAuth = new byte[20];
|
||||||
|
ByteBuffer buf = ByteBuffer.wrap(fingerprints);
|
||||||
|
buf.get(fpSign);
|
||||||
|
buf.get(fpDecrypt);
|
||||||
|
buf.get(fpAuth);
|
||||||
|
|
||||||
|
byte[] aid = getAid();
|
||||||
|
String userId = getUserId();
|
||||||
|
String url = getUrl();
|
||||||
|
byte[] pwInfo = getPwStatusBytes();
|
||||||
|
|
||||||
|
return SecurityTokenInfo.create(fpSign, fpDecrypt, fpAuth, aid, userId, url, pwInfo[4], pwInfo[6]);
|
||||||
|
}
|
||||||
|
|
||||||
private static class LazyHolder {
|
private static class LazyHolder {
|
||||||
private static final SecurityTokenHelper SECURITY_TOKEN_HELPER = new SecurityTokenHelper();
|
private static final SecurityTokenHelper SECURITY_TOKEN_HELPER = new SecurityTokenHelper();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package org.sufficientlysecure.keychain.securitytoken;
|
||||||
|
|
||||||
|
|
||||||
|
import android.os.Parcelable;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class SecurityTokenInfo implements Parcelable {
|
||||||
|
@Nullable
|
||||||
|
public abstract byte[] getFingerprintSign();
|
||||||
|
@Nullable
|
||||||
|
public abstract byte[] getFingerprintDecrypt();
|
||||||
|
@Nullable
|
||||||
|
public abstract byte[] getFingerprintAuth();
|
||||||
|
@Nullable
|
||||||
|
public abstract byte[] getAid();
|
||||||
|
@Nullable
|
||||||
|
public abstract String getUserId();
|
||||||
|
@Nullable
|
||||||
|
public abstract String getUrl();
|
||||||
|
public abstract int getVerifyRetries();
|
||||||
|
public abstract int getVerifyAdminRetries();
|
||||||
|
|
||||||
|
public byte[][] getAllFingerprints() {
|
||||||
|
byte[][] fingerprints = new byte[3][];
|
||||||
|
fingerprints[0] = getFingerprintSign();
|
||||||
|
fingerprints[1] = getFingerprintDecrypt();
|
||||||
|
fingerprints[2] = getFingerprintAuth();
|
||||||
|
return fingerprints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return getFingerprintSign() == null && getFingerprintDecrypt() == null && getFingerprintAuth() == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SecurityTokenInfo create(byte[] fpSign, byte[] fpDecrypt, byte[] fpAuth,
|
||||||
|
byte[] aid, String userId, String url, int verifyRetries, int verifyAdminRetries) {
|
||||||
|
return new AutoValue_SecurityTokenInfo(fpSign, fpDecrypt, fpAuth, aid,
|
||||||
|
userId, url, verifyRetries, verifyAdminRetries);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SecurityTokenInfo createBlank(byte[] aid) {
|
||||||
|
return new AutoValue_SecurityTokenInfo(null, null, null, aid, null, null, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,15 +31,10 @@ import android.support.v4.app.FragmentTransaction;
|
|||||||
import android.support.v4.app.TaskStackBuilder;
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
|
||||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
|
||||||
import org.sufficientlysecure.keychain.securitytoken.KeyFormat;
|
import org.sufficientlysecure.keychain.securitytoken.KeyFormat;
|
||||||
|
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo;
|
||||||
import org.sufficientlysecure.keychain.ui.base.BaseSecurityTokenActivity;
|
import org.sufficientlysecure.keychain.ui.base.BaseSecurityTokenActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.keyview.ViewKeyActivity;
|
|
||||||
import org.sufficientlysecure.keychain.ui.token.ManageSecurityTokenFragment;
|
import org.sufficientlysecure.keychain.ui.token.ManageSecurityTokenFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
@@ -54,10 +49,7 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity {
|
|||||||
public static final String EXTRA_SECURITY_TOKEN_PIN = "yubi_key_pin";
|
public static final String EXTRA_SECURITY_TOKEN_PIN = "yubi_key_pin";
|
||||||
public static final String EXTRA_SECURITY_TOKEN_ADMIN_PIN = "yubi_key_admin_pin";
|
public static final String EXTRA_SECURITY_TOKEN_ADMIN_PIN = "yubi_key_admin_pin";
|
||||||
|
|
||||||
public static final String EXTRA_SECURITY_TOKEN_USER_ID = "nfc_user_id";
|
public static final String EXTRA_SECURITY_TOKEN_INFO = "token_info";
|
||||||
public static final String EXTRA_SECURITY_TOKEN_AID = "nfc_aid";
|
|
||||||
public static final String EXTRA_SECURITY_FINGERPRINTS = "nfc_fingerprints";
|
|
||||||
public static final String EXTRA_SECURITY_TOKEN_URL = "nfc_url";
|
|
||||||
|
|
||||||
public static final String FRAGMENT_TAG = "currentFragment";
|
public static final String FRAGMENT_TAG = "currentFragment";
|
||||||
|
|
||||||
@@ -75,11 +67,7 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity {
|
|||||||
|
|
||||||
Fragment mCurrentFragment;
|
Fragment mCurrentFragment;
|
||||||
|
|
||||||
|
SecurityTokenInfo tokenInfo;
|
||||||
byte[] mScannedFingerprints;
|
|
||||||
byte[] mSecurityTokenAid;
|
|
||||||
String mSecurityTokenUserId;
|
|
||||||
private String mSecurityTokenUrl;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -106,7 +94,6 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity {
|
|||||||
mPassphrase = savedInstanceState.getParcelable(EXTRA_PASSPHRASE);
|
mPassphrase = savedInstanceState.getParcelable(EXTRA_PASSPHRASE);
|
||||||
mFirstTime = savedInstanceState.getBoolean(EXTRA_FIRST_TIME);
|
mFirstTime = savedInstanceState.getBoolean(EXTRA_FIRST_TIME);
|
||||||
mCreateSecurityToken = savedInstanceState.getBoolean(EXTRA_CREATE_SECURITY_TOKEN);
|
mCreateSecurityToken = savedInstanceState.getBoolean(EXTRA_CREATE_SECURITY_TOKEN);
|
||||||
mSecurityTokenAid = savedInstanceState.getByteArray(EXTRA_SECURITY_TOKEN_AID);
|
|
||||||
mSecurityTokenPin = savedInstanceState.getParcelable(EXTRA_SECURITY_TOKEN_PIN);
|
mSecurityTokenPin = savedInstanceState.getParcelable(EXTRA_SECURITY_TOKEN_PIN);
|
||||||
mSecurityTokenAdminPin = savedInstanceState.getParcelable(EXTRA_SECURITY_TOKEN_ADMIN_PIN);
|
mSecurityTokenAdminPin = savedInstanceState.getParcelable(EXTRA_SECURITY_TOKEN_ADMIN_PIN);
|
||||||
|
|
||||||
@@ -120,20 +107,16 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity {
|
|||||||
mFirstTime = intent.getBooleanExtra(EXTRA_FIRST_TIME, false);
|
mFirstTime = intent.getBooleanExtra(EXTRA_FIRST_TIME, false);
|
||||||
mCreateSecurityToken = intent.getBooleanExtra(EXTRA_CREATE_SECURITY_TOKEN, false);
|
mCreateSecurityToken = intent.getBooleanExtra(EXTRA_CREATE_SECURITY_TOKEN, false);
|
||||||
|
|
||||||
if (intent.hasExtra(EXTRA_SECURITY_FINGERPRINTS)) {
|
if (intent.hasExtra(EXTRA_SECURITY_TOKEN_INFO)) {
|
||||||
byte[] nfcFingerprints = intent.getByteArrayExtra(EXTRA_SECURITY_FINGERPRINTS);
|
SecurityTokenInfo tokenInfo = intent.getParcelableExtra(EXTRA_SECURITY_TOKEN_INFO);
|
||||||
String nfcUserId = intent.getStringExtra(EXTRA_SECURITY_TOKEN_USER_ID);
|
|
||||||
byte[] nfcAid = intent.getByteArrayExtra(EXTRA_SECURITY_TOKEN_AID);
|
|
||||||
String nfcUrl = intent.getStringExtra(EXTRA_SECURITY_TOKEN_URL);
|
|
||||||
|
|
||||||
if (containsKeys(nfcFingerprints)) {
|
if (!tokenInfo.isEmpty()) {
|
||||||
Fragment frag = ManageSecurityTokenFragment.newInstance(
|
Fragment frag = ManageSecurityTokenFragment.newInstance(tokenInfo);
|
||||||
nfcFingerprints, nfcAid, nfcUserId, nfcUrl);
|
|
||||||
loadFragment(frag, FragAction.START);
|
loadFragment(frag, FragAction.START);
|
||||||
|
|
||||||
setTitle(R.string.title_import_keys);
|
setTitle(R.string.title_import_keys);
|
||||||
} else {
|
} else {
|
||||||
Fragment frag = CreateSecurityTokenBlankFragment.newInstance(nfcAid);
|
Fragment frag = CreateSecurityTokenBlankFragment.newInstance();
|
||||||
loadFragment(frag, FragAction.START);
|
loadFragment(frag, FragAction.START);
|
||||||
setTitle(R.string.title_manage_my_keys);
|
setTitle(R.string.title_manage_my_keys);
|
||||||
}
|
}
|
||||||
@@ -163,10 +146,7 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mScannedFingerprints = mSecurityTokenHelper.getFingerprints();
|
tokenInfo = mSecurityTokenHelper.getTokenInfo();
|
||||||
mSecurityTokenAid = mSecurityTokenHelper.getAid();
|
|
||||||
mSecurityTokenUserId = mSecurityTokenHelper.getUserId();
|
|
||||||
mSecurityTokenUrl = mSecurityTokenHelper.getUrl();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -184,30 +164,15 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity {
|
|||||||
CreateSecurityTokenWaitFragment.sDisableFragmentAnimations = false;
|
CreateSecurityTokenWaitFragment.sDisableFragmentAnimations = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (containsKeys(mScannedFingerprints)) {
|
if (!tokenInfo.isEmpty()) {
|
||||||
Fragment frag = ManageSecurityTokenFragment.newInstance(
|
Fragment frag = ManageSecurityTokenFragment.newInstance(tokenInfo);
|
||||||
mScannedFingerprints, mSecurityTokenAid, mSecurityTokenUserId, mSecurityTokenUrl);
|
|
||||||
loadFragment(frag, FragAction.TO_RIGHT);
|
loadFragment(frag, FragAction.TO_RIGHT);
|
||||||
} else {
|
} else {
|
||||||
Fragment frag = CreateSecurityTokenBlankFragment.newInstance(mSecurityTokenAid);
|
Fragment frag = CreateSecurityTokenBlankFragment.newInstance();
|
||||||
loadFragment(frag, FragAction.TO_RIGHT);
|
loadFragment(frag, FragAction.TO_RIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean containsKeys(byte[] scannedFingerprints) {
|
|
||||||
if (scannedFingerprints == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If all fingerprint bytes are 0, the card contains no keys.
|
|
||||||
for (byte b : scannedFingerprints) {
|
|
||||||
if (b != 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
@@ -218,7 +183,6 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity {
|
|||||||
outState.putParcelable(EXTRA_PASSPHRASE, mPassphrase);
|
outState.putParcelable(EXTRA_PASSPHRASE, mPassphrase);
|
||||||
outState.putBoolean(EXTRA_FIRST_TIME, mFirstTime);
|
outState.putBoolean(EXTRA_FIRST_TIME, mFirstTime);
|
||||||
outState.putBoolean(EXTRA_CREATE_SECURITY_TOKEN, mCreateSecurityToken);
|
outState.putBoolean(EXTRA_CREATE_SECURITY_TOKEN, mCreateSecurityToken);
|
||||||
outState.putByteArray(EXTRA_SECURITY_TOKEN_AID, mSecurityTokenAid);
|
|
||||||
outState.putParcelable(EXTRA_SECURITY_TOKEN_PIN, mSecurityTokenPin);
|
outState.putParcelable(EXTRA_SECURITY_TOKEN_PIN, mSecurityTokenPin);
|
||||||
outState.putParcelable(EXTRA_SECURITY_TOKEN_ADMIN_PIN, mSecurityTokenAdminPin);
|
outState.putParcelable(EXTRA_SECURITY_TOKEN_ADMIN_PIN, mSecurityTokenAdminPin);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class CreateSecurityTokenAlgorithmFragment extends Fragment {
|
|||||||
choices.add(new Choice<>(SupportedKeyType.RSA_4096, getResources().getString(
|
choices.add(new Choice<>(SupportedKeyType.RSA_4096, getResources().getString(
|
||||||
R.string.rsa_4096), getResources().getString(R.string.rsa_4096_description_html)));
|
R.string.rsa_4096), getResources().getString(R.string.rsa_4096_description_html)));
|
||||||
|
|
||||||
final double version = SecurityTokenHelper.parseOpenPgpVersion(mCreateKeyActivity.mSecurityTokenAid);
|
final double version = SecurityTokenHelper.parseOpenPgpVersion(mCreateKeyActivity.tokenInfo.getAid());
|
||||||
|
|
||||||
if (version >= 3.0) {
|
if (version >= 3.0) {
|
||||||
choices.add(new Choice<>(SupportedKeyType.ECC_P256, getResources().getString(
|
choices.add(new Choice<>(SupportedKeyType.ECC_P256, getResources().getString(
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -34,20 +35,11 @@ public class CreateSecurityTokenBlankFragment extends Fragment {
|
|||||||
View mBackButton;
|
View mBackButton;
|
||||||
View mNextButton;
|
View mNextButton;
|
||||||
|
|
||||||
private byte[] mAid;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new instance of this fragment
|
* Creates new instance of this fragment
|
||||||
*/
|
*/
|
||||||
public static CreateSecurityTokenBlankFragment newInstance(byte[] aid) {
|
public static CreateSecurityTokenBlankFragment newInstance() {
|
||||||
CreateSecurityTokenBlankFragment frag = new CreateSecurityTokenBlankFragment();
|
return new CreateSecurityTokenBlankFragment();
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
|
|
||||||
frag.mAid = aid;
|
|
||||||
frag.setArguments(args);
|
|
||||||
|
|
||||||
return frag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -86,7 +78,6 @@ public class CreateSecurityTokenBlankFragment extends Fragment {
|
|||||||
|
|
||||||
private void nextClicked() {
|
private void nextClicked() {
|
||||||
mCreateKeyActivity.mCreateSecurityToken = true;
|
mCreateKeyActivity.mCreateSecurityToken = true;
|
||||||
mCreateKeyActivity.mSecurityTokenAid = mAid;
|
|
||||||
|
|
||||||
CreateKeyNameFragment frag = CreateKeyNameFragment.newInstance();
|
CreateKeyNameFragment frag = CreateKeyNameFragment.newInstance();
|
||||||
mCreateKeyActivity.loadFragment(frag, FragAction.TO_RIGHT);
|
mCreateKeyActivity.loadFragment(frag, FragAction.TO_RIGHT);
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ public class CreateSecurityTokenPinFragment extends Fragment {
|
|||||||
|
|
||||||
mCreateKeyActivity.mSecurityTokenPin = new Passphrase(mPin.getText().toString());
|
mCreateKeyActivity.mSecurityTokenPin = new Passphrase(mPin.getText().toString());
|
||||||
|
|
||||||
final double version = SecurityTokenHelper.parseOpenPgpVersion(mCreateKeyActivity.mSecurityTokenAid);
|
final double version = SecurityTokenHelper.parseOpenPgpVersion(mCreateKeyActivity.tokenInfo.getAid());
|
||||||
|
|
||||||
Fragment frag;
|
Fragment frag;
|
||||||
if (version >= 3.0) {
|
if (version >= 3.0) {
|
||||||
|
|||||||
@@ -41,13 +41,10 @@ import nordpol.android.TagDispatcher;
|
|||||||
import nordpol.android.TagDispatcherBuilder;
|
import nordpol.android.TagDispatcherBuilder;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
|
||||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
|
||||||
import org.sufficientlysecure.keychain.securitytoken.CardException;
|
import org.sufficientlysecure.keychain.securitytoken.CardException;
|
||||||
import org.sufficientlysecure.keychain.securitytoken.NfcTransport;
|
import org.sufficientlysecure.keychain.securitytoken.NfcTransport;
|
||||||
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenHelper;
|
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenHelper;
|
||||||
|
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo;
|
||||||
import org.sufficientlysecure.keychain.securitytoken.Transport;
|
import org.sufficientlysecure.keychain.securitytoken.Transport;
|
||||||
import org.sufficientlysecure.keychain.securitytoken.UsbConnectionDispatcher;
|
import org.sufficientlysecure.keychain.securitytoken.UsbConnectionDispatcher;
|
||||||
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransport;
|
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransport;
|
||||||
@@ -56,10 +53,8 @@ import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
|||||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity;
|
import org.sufficientlysecure.keychain.ui.CreateKeyActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
|
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.keyview.ViewKeyActivity;
|
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.FidesmoInstallDialog;
|
import org.sufficientlysecure.keychain.ui.dialog.FidesmoInstallDialog;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.FidesmoPgpInstallDialog;
|
import org.sufficientlysecure.keychain.ui.dialog.FidesmoPgpInstallDialog;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
|
||||||
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.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
@@ -78,10 +73,7 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity
|
|||||||
protected UsbConnectionDispatcher mUsbDispatcher;
|
protected UsbConnectionDispatcher mUsbDispatcher;
|
||||||
private boolean mTagHandlingEnabled;
|
private boolean mTagHandlingEnabled;
|
||||||
|
|
||||||
private byte[] mSecurityTokenFingerprints;
|
private SecurityTokenInfo tokenInfo;
|
||||||
private String mSecurityTokenUserId;
|
|
||||||
private byte[] mSecurityTokenAid;
|
|
||||||
private String mSecurityTokenUrl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override to change UI before SecurityToken handling (UI thread)
|
* Override to change UI before SecurityToken handling (UI thread)
|
||||||
@@ -93,10 +85,8 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity
|
|||||||
* Override to implement SecurityToken operations (background thread)
|
* Override to implement SecurityToken operations (background thread)
|
||||||
*/
|
*/
|
||||||
protected void doSecurityTokenInBackground() throws IOException {
|
protected void doSecurityTokenInBackground() throws IOException {
|
||||||
mSecurityTokenAid = mSecurityTokenHelper.getAid();
|
tokenInfo = mSecurityTokenHelper.getTokenInfo();
|
||||||
mSecurityTokenFingerprints = mSecurityTokenHelper.getFingerprints();
|
Log.d(Constants.TAG, "Security Token: " + tokenInfo);
|
||||||
mSecurityTokenUserId = mSecurityTokenHelper.getUserId();
|
|
||||||
mSecurityTokenUrl = mSecurityTokenHelper.getUrl();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,10 +94,7 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity
|
|||||||
*/
|
*/
|
||||||
protected void onSecurityTokenPostExecute() {
|
protected void onSecurityTokenPostExecute() {
|
||||||
Intent intent = new Intent(this, CreateKeyActivity.class);
|
Intent intent = new Intent(this, CreateKeyActivity.class);
|
||||||
intent.putExtra(CreateKeyActivity.EXTRA_SECURITY_FINGERPRINTS, mSecurityTokenFingerprints);
|
intent.putExtra(CreateKeyActivity.EXTRA_SECURITY_TOKEN_INFO, tokenInfo);
|
||||||
intent.putExtra(CreateKeyActivity.EXTRA_SECURITY_TOKEN_AID, mSecurityTokenAid);
|
|
||||||
intent.putExtra(CreateKeyActivity.EXTRA_SECURITY_TOKEN_USER_ID, mSecurityTokenUserId);
|
|
||||||
intent.putExtra(CreateKeyActivity.EXTRA_SECURITY_TOKEN_URL, mSecurityTokenUrl);
|
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
|||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.PromoteKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.PromoteKeyResult;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
|
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo;
|
||||||
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.service.PromoteKeyringParcel;
|
import org.sufficientlysecure.keychain.service.PromoteKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
@@ -72,10 +73,7 @@ import org.sufficientlysecure.keychain.util.FileHelper;
|
|||||||
|
|
||||||
public class ManageSecurityTokenFragment extends Fragment implements ManageSecurityTokenMvpView,
|
public class ManageSecurityTokenFragment extends Fragment implements ManageSecurityTokenMvpView,
|
||||||
OnClickListener {
|
OnClickListener {
|
||||||
private static final String ARG_FINGERPRINTS = "fingerprint";
|
private static final String ARG_TOKEN_INFO = "token_info";
|
||||||
private static final String ARG_AID = "aid";
|
|
||||||
private static final String ARG_USER_ID = "user_ids";
|
|
||||||
private static final String ARG_URL = "key_uri";
|
|
||||||
public static final int REQUEST_CODE_OPEN_FILE = 0;
|
public static final int REQUEST_CODE_OPEN_FILE = 0;
|
||||||
public static final int REQUEST_CODE_RESET = 1;
|
public static final int REQUEST_CODE_RESET = 1;
|
||||||
public static final int PERMISSION_READ_STORAGE = 0;
|
public static final int PERMISSION_READ_STORAGE = 0;
|
||||||
@@ -93,29 +91,29 @@ public class ManageSecurityTokenFragment extends Fragment implements ManageSecur
|
|||||||
if (!BuildConfig.DEBUG) {
|
if (!BuildConfig.DEBUG) {
|
||||||
throw new UnsupportedOperationException("This operation is only available in debug builds!");
|
throw new UnsupportedOperationException("This operation is only available in debug builds!");
|
||||||
}
|
}
|
||||||
byte[] scannedFps =
|
SecurityTokenInfo securityTokenInfo = SecurityTokenInfo.create(
|
||||||
KeyFormattingUtils.convertFingerprintHexFingerprint("1efdb4845ca242ca6977fddb1f788094fd3b430a");
|
KeyFormattingUtils.convertFingerprintHexFingerprint("1efdb4845ca242ca6977fddb1f788094fd3b430a"),
|
||||||
return newInstance(scannedFps, Hex.decode("010203040506"), "yubinu2@mugenguild.com", null);
|
new byte[20], new byte[20], Hex.decode("010203040506"),
|
||||||
|
"yubinu2@mugenguild.com", "http://valodim.stratum0.net/mryubinu2.asc", 3, 3);
|
||||||
|
return newInstance(securityTokenInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Fragment newInstanceDebugUri() {
|
public static Fragment newInstanceDebugUri() {
|
||||||
if (!BuildConfig.DEBUG) {
|
if (!BuildConfig.DEBUG) {
|
||||||
throw new UnsupportedOperationException("This operation is only available in debug builds!");
|
throw new UnsupportedOperationException("This operation is only available in debug builds!");
|
||||||
}
|
}
|
||||||
byte[] scannedFps =
|
SecurityTokenInfo securityTokenInfo = SecurityTokenInfo.create(
|
||||||
KeyFormattingUtils.convertFingerprintHexFingerprint("4700BA1AC417ABEF3CC7765AD686905837779C3E");
|
KeyFormattingUtils.convertFingerprintHexFingerprint("4700BA1AC417ABEF3CC7765AD686905837779C3E"),
|
||||||
return newInstance(scannedFps, Hex.decode("010203040506"), "yubinu2@mugenguild.com",
|
new byte[20], new byte[20], Hex.decode("010203040506"),
|
||||||
"http://valodim.stratum0.net/mryubinu2.asc");
|
"yubinu2@mugenguild.com", "http://valodim.stratum0.net/mryubinu2.asc", 3, 3);
|
||||||
|
return newInstance(securityTokenInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Fragment newInstance(byte[] scannedFingerprints, byte[] nfcAid, String userId, String tokenUrl) {
|
public static Fragment newInstance(SecurityTokenInfo tokenInfo) {
|
||||||
ManageSecurityTokenFragment frag = new ManageSecurityTokenFragment();
|
ManageSecurityTokenFragment frag = new ManageSecurityTokenFragment();
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putByteArray(ARG_FINGERPRINTS, scannedFingerprints);
|
args.putParcelable(ARG_TOKEN_INFO, tokenInfo);
|
||||||
args.putByteArray(ARG_AID, nfcAid);
|
|
||||||
args.putString(ARG_USER_ID, userId);
|
|
||||||
args.putString(ARG_URL, tokenUrl);
|
|
||||||
frag.setArguments(args);
|
frag.setArguments(args);
|
||||||
|
|
||||||
return frag;
|
return frag;
|
||||||
@@ -126,14 +124,9 @@ public class ManageSecurityTokenFragment extends Fragment implements ManageSecur
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
|
SecurityTokenInfo tokenInfo = args.getParcelable(ARG_TOKEN_INFO);
|
||||||
|
|
||||||
byte[] tokenFingerprints = args.getByteArray(ARG_FINGERPRINTS);
|
presenter = new ManageSecurityTokenPresenter(getContext(), getLoaderManager(), tokenInfo);
|
||||||
byte[] tokenAid = args.getByteArray(ARG_AID);
|
|
||||||
String tokenUserId = args.getString(ARG_USER_ID);
|
|
||||||
String tokenUrl = args.getString(ARG_URL);
|
|
||||||
|
|
||||||
presenter = new ManageSecurityTokenPresenter(
|
|
||||||
getContext(), tokenFingerprints, tokenAid, tokenUserId, tokenUrl, getLoaderManager());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import android.support.v4.content.Loader;
|
|||||||
import org.sufficientlysecure.keychain.operations.results.GenericOperationResult;
|
import org.sufficientlysecure.keychain.operations.results.GenericOperationResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||||
|
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo;
|
||||||
import org.sufficientlysecure.keychain.ui.token.ManageSecurityTokenContract.ManageSecurityTokenMvpPresenter;
|
import org.sufficientlysecure.keychain.ui.token.ManageSecurityTokenContract.ManageSecurityTokenMvpPresenter;
|
||||||
import org.sufficientlysecure.keychain.ui.token.ManageSecurityTokenContract.ManageSecurityTokenMvpView;
|
import org.sufficientlysecure.keychain.ui.token.ManageSecurityTokenContract.ManageSecurityTokenMvpView;
|
||||||
import org.sufficientlysecure.keychain.ui.token.ManageSecurityTokenFragment.StatusLine;
|
import org.sufficientlysecure.keychain.ui.token.ManageSecurityTokenFragment.StatusLine;
|
||||||
@@ -49,11 +50,7 @@ class ManageSecurityTokenPresenter implements ManageSecurityTokenMvpPresenter {
|
|||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final LoaderManager loaderManager;
|
private final LoaderManager loaderManager;
|
||||||
|
private final SecurityTokenInfo tokenInfo;
|
||||||
private final byte[][] tokenFingerprints;
|
|
||||||
private final byte[] tokenAid;
|
|
||||||
private final String tokenUserId;
|
|
||||||
private final String tokenUrl;
|
|
||||||
|
|
||||||
|
|
||||||
private ManageSecurityTokenMvpView view;
|
private ManageSecurityTokenMvpView view;
|
||||||
@@ -68,23 +65,10 @@ class ManageSecurityTokenPresenter implements ManageSecurityTokenMvpPresenter {
|
|||||||
private OperationLog log;
|
private OperationLog log;
|
||||||
private Uri selectedContentUri;
|
private Uri selectedContentUri;
|
||||||
|
|
||||||
ManageSecurityTokenPresenter(Context context, byte[] tokenFingerprints, byte[] tokenAid,
|
ManageSecurityTokenPresenter(Context context, LoaderManager loaderManager, SecurityTokenInfo tokenInfo) {
|
||||||
String tokenUserId, String tokenUrl, LoaderManager loaderManager) {
|
|
||||||
this.context = context.getApplicationContext();
|
this.context = context.getApplicationContext();
|
||||||
|
|
||||||
this.tokenAid = tokenAid;
|
|
||||||
this.tokenUserId = tokenUserId;
|
|
||||||
this.tokenUrl = tokenUrl;
|
|
||||||
this.loaderManager = loaderManager;
|
this.loaderManager = loaderManager;
|
||||||
|
this.tokenInfo = tokenInfo;
|
||||||
if (tokenFingerprints.length % 20 != 0) {
|
|
||||||
throw new IllegalArgumentException("fingerprints must be multiple of 20 bytes!");
|
|
||||||
}
|
|
||||||
this.tokenFingerprints = new byte[tokenFingerprints.length / 20][];
|
|
||||||
for (int i = 0; i < tokenFingerprints.length / 20; i++) {
|
|
||||||
this.tokenFingerprints[i] = new byte[20];
|
|
||||||
System.arraycopy(tokenFingerprints, i*20, this.tokenFingerprints[i], 0, 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.log = new OperationLog();
|
this.log = new OperationLog();
|
||||||
}
|
}
|
||||||
@@ -133,13 +117,13 @@ class ManageSecurityTokenPresenter implements ManageSecurityTokenMvpPresenter {
|
|||||||
public Loader<KeyRetrievalResult> onCreateLoader(int id, Bundle args) {
|
public Loader<KeyRetrievalResult> onCreateLoader(int id, Bundle args) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case LOADER_LOCAL:
|
case LOADER_LOCAL:
|
||||||
return new LocalKeyLookupLoader(context, tokenFingerprints);
|
return new LocalKeyLookupLoader(context, tokenInfo.getAllFingerprints());
|
||||||
case LOADER_URI:
|
case LOADER_URI:
|
||||||
return new UriKeyRetrievalLoader(context, tokenUrl, tokenFingerprints);
|
return new UriKeyRetrievalLoader(context, tokenInfo.getUrl(), tokenInfo.getAllFingerprints());
|
||||||
case LOADER_KEYSERVER:
|
case LOADER_KEYSERVER:
|
||||||
return new KeyserverRetrievalLoader(context, tokenFingerprints[0]);
|
return new KeyserverRetrievalLoader(context, tokenInfo.getFingerprintSign());
|
||||||
case LOADER_CONTENT_URI:
|
case LOADER_CONTENT_URI:
|
||||||
return new ContentUriRetrievalLoader(context, tokenFingerprints[0],
|
return new ContentUriRetrievalLoader(context, tokenInfo.getFingerprintSign(),
|
||||||
args.<Uri>getParcelable(ARG_CONTENT_URI));
|
args.<Uri>getParcelable(ARG_CONTENT_URI));
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("called with unknown loader id!");
|
throw new IllegalArgumentException("called with unknown loader id!");
|
||||||
@@ -203,7 +187,7 @@ class ManageSecurityTokenPresenter implements ManageSecurityTokenMvpPresenter {
|
|||||||
if (masterKeyId != null) {
|
if (masterKeyId != null) {
|
||||||
this.masterKeyId = masterKeyId;
|
this.masterKeyId = masterKeyId;
|
||||||
view.statusLineAdd(StatusLine.TOKEN_CHECK);
|
view.statusLineAdd(StatusLine.TOKEN_CHECK);
|
||||||
view.operationPromote(masterKeyId, tokenAid);
|
view.operationPromote(masterKeyId, tokenInfo.getAid());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +207,7 @@ class ManageSecurityTokenPresenter implements ManageSecurityTokenMvpPresenter {
|
|||||||
|
|
||||||
view.statusLineOk();
|
view.statusLineOk();
|
||||||
view.statusLineAdd(StatusLine.TOKEN_PROMOTE);
|
view.statusLineAdd(StatusLine.TOKEN_PROMOTE);
|
||||||
view.operationPromote(masterKeyId, tokenAid);
|
view.operationPromote(masterKeyId, tokenInfo.getAid());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user