OTG: Rename 'javacard' package, methods, remove JavacardInterface
This commit is contained in:
@@ -149,9 +149,9 @@ public class CreateKeyActivity extends BaseSecurityTokenNfcActivity {
|
||||
return;
|
||||
}
|
||||
|
||||
mScannedFingerprints = mJavacardDevice.getFingerprints();
|
||||
mNfcAid = mJavacardDevice.getAid();
|
||||
mNfcUserId = mJavacardDevice.getUserId();
|
||||
mScannedFingerprints = mSmartcardDevice.getFingerprints();
|
||||
mNfcAid = mSmartcardDevice.getAid();
|
||||
mNfcUserId = mSmartcardDevice.getUserId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.ArrayList;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -250,9 +249,9 @@ public class CreateSecurityTokenImportResetFragment
|
||||
@Override
|
||||
public void doNfcInBackground() throws IOException {
|
||||
|
||||
mTokenFingerprints = mCreateKeyActivity.mJavacardDevice.getFingerprints();
|
||||
mTokenAid = mCreateKeyActivity.mJavacardDevice.getAid();
|
||||
mTokenUserId = mCreateKeyActivity.mJavacardDevice.getUserId();
|
||||
mTokenFingerprints = mCreateKeyActivity.mSmartcardDevice.getFingerprints();
|
||||
mTokenAid = mCreateKeyActivity.mSmartcardDevice.getAid();
|
||||
mTokenUserId = mCreateKeyActivity.mSmartcardDevice.getUserId();
|
||||
|
||||
byte[] fp = new byte[20];
|
||||
ByteBuffer.wrap(fp).put(mTokenFingerprints, 0, 20);
|
||||
|
||||
@@ -162,7 +162,7 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenNfcActivity
|
||||
case NFC_DECRYPT: {
|
||||
for (int i = 0; i < mRequiredInput.mInputData.length; i++) {
|
||||
byte[] encryptedSessionKey = mRequiredInput.mInputData[i];
|
||||
byte[] decryptedSessionKey = mJavacardDevice.decryptSessionKey(encryptedSessionKey);
|
||||
byte[] decryptedSessionKey = mSmartcardDevice.decryptSessionKey(encryptedSessionKey);
|
||||
mInputParcel.addCryptoData(encryptedSessionKey, decryptedSessionKey);
|
||||
}
|
||||
break;
|
||||
@@ -173,15 +173,15 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenNfcActivity
|
||||
for (int i = 0; i < mRequiredInput.mInputData.length; i++) {
|
||||
byte[] hash = mRequiredInput.mInputData[i];
|
||||
int algo = mRequiredInput.mSignAlgos[i];
|
||||
byte[] signedHash = mJavacardDevice.calculateSignature(hash, algo);
|
||||
byte[] signedHash = mSmartcardDevice.calculateSignature(hash, algo);
|
||||
mInputParcel.addCryptoData(hash, signedHash);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NFC_MOVE_KEY_TO_CARD: {
|
||||
// TODO: assume PIN and Admin PIN to be default for this operation
|
||||
mJavacardDevice.setPin(new Passphrase("123456"));
|
||||
mJavacardDevice.setAdminPin(new Passphrase("12345678"));
|
||||
mSmartcardDevice.setPin(new Passphrase("123456"));
|
||||
mSmartcardDevice.setAdminPin(new Passphrase("12345678"));
|
||||
|
||||
ProviderHelper providerHelper = new ProviderHelper(this);
|
||||
CanonicalizedSecretKeyRing secretKeyRing;
|
||||
@@ -206,7 +206,7 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenNfcActivity
|
||||
long keyGenerationTimestampMillis = key.getCreationTime().getTime();
|
||||
long keyGenerationTimestamp = keyGenerationTimestampMillis / 1000;
|
||||
byte[] timestampBytes = ByteBuffer.allocate(4).putInt((int) keyGenerationTimestamp).array();
|
||||
byte[] tokenSerialNumber = Arrays.copyOf(mJavacardDevice.getAid(), 16);
|
||||
byte[] tokenSerialNumber = Arrays.copyOf(mSmartcardDevice.getAid(), 16);
|
||||
|
||||
Passphrase passphrase;
|
||||
try {
|
||||
@@ -218,25 +218,25 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenNfcActivity
|
||||
|
||||
if (key.canSign() || key.canCertify()) {
|
||||
if (shouldPutKey(key.getFingerprint(), 0)) {
|
||||
mJavacardDevice.putKey(0xB6, key, passphrase);
|
||||
mJavacardDevice.putData(0xCE, timestampBytes);
|
||||
mJavacardDevice.putData(0xC7, key.getFingerprint());
|
||||
mSmartcardDevice.putKey(0xB6, key, passphrase);
|
||||
mSmartcardDevice.putData(0xCE, timestampBytes);
|
||||
mSmartcardDevice.putData(0xC7, key.getFingerprint());
|
||||
} else {
|
||||
throw new IOException("Key slot occupied; token must be reset to put new signature key.");
|
||||
}
|
||||
} else if (key.canEncrypt()) {
|
||||
if (shouldPutKey(key.getFingerprint(), 1)) {
|
||||
mJavacardDevice.putKey(0xB8, key, passphrase);
|
||||
mJavacardDevice.putData(0xCF, timestampBytes);
|
||||
mJavacardDevice.putData(0xC8, key.getFingerprint());
|
||||
mSmartcardDevice.putKey(0xB8, key, passphrase);
|
||||
mSmartcardDevice.putData(0xCF, timestampBytes);
|
||||
mSmartcardDevice.putData(0xC8, key.getFingerprint());
|
||||
} else {
|
||||
throw new IOException("Key slot occupied; token must be reset to put new decryption key.");
|
||||
}
|
||||
} else if (key.canAuthenticate()) {
|
||||
if (shouldPutKey(key.getFingerprint(), 2)) {
|
||||
mJavacardDevice.putKey(0xA4, key, passphrase);
|
||||
mJavacardDevice.putData(0xD0, timestampBytes);
|
||||
mJavacardDevice.putData(0xC9, key.getFingerprint());
|
||||
mSmartcardDevice.putKey(0xA4, key, passphrase);
|
||||
mSmartcardDevice.putData(0xD0, timestampBytes);
|
||||
mSmartcardDevice.putData(0xC9, key.getFingerprint());
|
||||
} else {
|
||||
throw new IOException("Key slot occupied; token must be reset to put new authentication key.");
|
||||
}
|
||||
@@ -249,13 +249,13 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenNfcActivity
|
||||
}
|
||||
|
||||
// change PINs afterwards
|
||||
mJavacardDevice.modifyPin(0x81, newPin);
|
||||
mJavacardDevice.modifyPin(0x83, newAdminPin);
|
||||
mSmartcardDevice.modifyPin(0x81, newPin);
|
||||
mSmartcardDevice.modifyPin(0x83, newAdminPin);
|
||||
|
||||
break;
|
||||
}
|
||||
case NFC_RESET_CARD: {
|
||||
mJavacardDevice.resetAndWipeToken();
|
||||
mSmartcardDevice.resetAndWipeToken();
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -330,7 +330,7 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenNfcActivity
|
||||
}
|
||||
|
||||
private boolean shouldPutKey(byte[] fingerprint, int idx) throws IOException {
|
||||
byte[] tokenFingerprint = mJavacardDevice.getMasterKeyFingerprint(idx);
|
||||
byte[] tokenFingerprint = mSmartcardDevice.getMasterKeyFingerprint(idx);
|
||||
|
||||
// Note: special case: This should not happen, but happens with
|
||||
// https://github.com/FluffyKaon/OpenPGP-Card, thus for now assume true
|
||||
|
||||
@@ -649,9 +649,9 @@ public class ViewKeyActivity extends BaseSecurityTokenNfcActivity implements
|
||||
@Override
|
||||
protected void doNfcInBackground() throws IOException {
|
||||
|
||||
mNfcFingerprints = mJavacardDevice.getFingerprints();
|
||||
mNfcUserId = mJavacardDevice.getUserId();
|
||||
mNfcAid = mJavacardDevice.getAid();
|
||||
mNfcFingerprints = mSmartcardDevice.getFingerprints();
|
||||
mNfcUserId = mSmartcardDevice.getUserId();
|
||||
mNfcAid = mSmartcardDevice.getAid();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
package org.sufficientlysecure.keychain.ui.base;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.usb.UsbDevice;
|
||||
@@ -35,12 +34,6 @@ import android.os.Bundle;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.javacard.BaseJavacardDevice;
|
||||
import org.sufficientlysecure.keychain.javacard.JavacardDevice;
|
||||
import org.sufficientlysecure.keychain.javacard.NfcTransport;
|
||||
import org.sufficientlysecure.keychain.javacard.OnDiscoveredUsbDeviceListener;
|
||||
import org.sufficientlysecure.keychain.javacard.UsbConnectionManager;
|
||||
import org.sufficientlysecure.keychain.javacard.UsbTransport;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
@@ -48,6 +41,11 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
import org.sufficientlysecure.keychain.smartcard.SmartcardDevice;
|
||||
import org.sufficientlysecure.keychain.smartcard.NfcTransport;
|
||||
import org.sufficientlysecure.keychain.smartcard.OnDiscoveredUsbDeviceListener;
|
||||
import org.sufficientlysecure.keychain.smartcard.UsbConnectionManager;
|
||||
import org.sufficientlysecure.keychain.smartcard.UsbTransport;
|
||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity;
|
||||
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
|
||||
import org.sufficientlysecure.keychain.ui.ViewKeyActivity;
|
||||
@@ -74,7 +72,7 @@ public abstract class BaseSecurityTokenNfcActivity extends BaseActivity
|
||||
|
||||
private static final String FIDESMO_APP_PACKAGE = "com.fidesmo.sec.android";
|
||||
|
||||
public JavacardDevice mJavacardDevice = new BaseJavacardDevice();
|
||||
public SmartcardDevice mSmartcardDevice = new SmartcardDevice();
|
||||
protected TagDispatcher mTagDispatcher;
|
||||
protected UsbConnectionManager mUsbDispatcher;
|
||||
private boolean mTagHandlingEnabled;
|
||||
@@ -93,9 +91,9 @@ public abstract class BaseSecurityTokenNfcActivity extends BaseActivity
|
||||
* Override to implement NFC operations (background thread)
|
||||
*/
|
||||
protected void doNfcInBackground() throws IOException {
|
||||
mNfcFingerprints = mJavacardDevice.getFingerprints();
|
||||
mNfcUserId = mJavacardDevice.getUserId();
|
||||
mNfcAid = mJavacardDevice.getAid();
|
||||
mNfcFingerprints = mSmartcardDevice.getFingerprints();
|
||||
mNfcUserId = mSmartcardDevice.getUserId();
|
||||
mNfcAid = mSmartcardDevice.getAid();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +139,7 @@ public abstract class BaseSecurityTokenNfcActivity extends BaseActivity
|
||||
|
||||
public void tagDiscovered(final Tag tag) {
|
||||
// Actual NFC operations are executed in doInBackground to not block the UI thread
|
||||
if(!mTagHandlingEnabled)
|
||||
if (!mTagHandlingEnabled)
|
||||
return;
|
||||
new AsyncTask<Void, Void, IOException>() {
|
||||
@Override
|
||||
@@ -178,7 +176,7 @@ public abstract class BaseSecurityTokenNfcActivity extends BaseActivity
|
||||
|
||||
public void usbDeviceDiscovered(final UsbDevice device) {
|
||||
// Actual NFC operations are executed in doInBackground to not block the UI thread
|
||||
if(!mTagHandlingEnabled)
|
||||
if (!mTagHandlingEnabled)
|
||||
return;
|
||||
new AsyncTask<Void, Void, IOException>() {
|
||||
@Override
|
||||
@@ -347,7 +345,7 @@ public abstract class BaseSecurityTokenNfcActivity extends BaseActivity
|
||||
}
|
||||
// 6A82 app not installed on security token!
|
||||
case 0x6A82: {
|
||||
if (mJavacardDevice.isFidesmoToken()) {
|
||||
if (mSmartcardDevice.isFidesmoToken()) {
|
||||
// Check if the Fidesmo app is installed
|
||||
if (isAndroidAppInstalled(FIDESMO_APP_PACKAGE)) {
|
||||
promptFidesmoPgpInstall();
|
||||
@@ -396,7 +394,7 @@ public abstract class BaseSecurityTokenNfcActivity extends BaseActivity
|
||||
Passphrase passphrase = PassphraseCacheService.getCachedPassphrase(this,
|
||||
requiredInput.getMasterKeyId(), requiredInput.getSubKeyId());
|
||||
if (passphrase != null) {
|
||||
mJavacardDevice.setPin(passphrase);
|
||||
mSmartcardDevice.setPin(passphrase);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -421,7 +419,7 @@ public abstract class BaseSecurityTokenNfcActivity extends BaseActivity
|
||||
return;
|
||||
}
|
||||
CryptoInputParcel input = data.getParcelableExtra(PassphraseDialogActivity.RESULT_CRYPTO_INPUT);
|
||||
mJavacardDevice.setPin(input.getPassphrase());
|
||||
mSmartcardDevice.setPin(input.getPassphrase());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -429,19 +427,19 @@ public abstract class BaseSecurityTokenNfcActivity extends BaseActivity
|
||||
}
|
||||
}
|
||||
|
||||
/** Handle NFC communication and return a result.
|
||||
*
|
||||
/**
|
||||
* Handle NFC communication and return a result.
|
||||
* <p/>
|
||||
* This method is called by onNewIntent above upon discovery of an NFC tag.
|
||||
* It handles initialization and login to the application, subsequently
|
||||
* calls either nfcCalculateSignature() or nfcDecryptSessionKey(), then
|
||||
* finishes the activity with an appropriate result.
|
||||
*
|
||||
* <p/>
|
||||
* On general communication, see also
|
||||
* http://www.cardwerk.com/smartcards/smartcard_standard_ISO7816-4_annex-a.aspx
|
||||
*
|
||||
* <p/>
|
||||
* References to pages are generally related to the OpenPGP Application
|
||||
* on ISO SmartCard Systems specification.
|
||||
*
|
||||
*/
|
||||
protected void handleTagDiscovered(Tag tag) throws IOException {
|
||||
|
||||
@@ -451,22 +449,22 @@ public abstract class BaseSecurityTokenNfcActivity extends BaseActivity
|
||||
throw new IsoDepNotSupportedException("Tag does not support ISO-DEP (ISO 14443-4)");
|
||||
}
|
||||
|
||||
mJavacardDevice.setTransport(new NfcTransport(isoCard));
|
||||
mJavacardDevice.connectToDevice();
|
||||
mSmartcardDevice.setTransport(new NfcTransport(isoCard));
|
||||
mSmartcardDevice.connectToDevice();
|
||||
|
||||
doNfcInBackground();
|
||||
}
|
||||
|
||||
protected void handleUsbDevice(UsbDevice device) throws IOException {
|
||||
UsbManager usbManager = (UsbManager) getSystemService(USB_SERVICE);
|
||||
mJavacardDevice.setTransport(new UsbTransport(device, usbManager));
|
||||
mJavacardDevice.connectToDevice();
|
||||
mSmartcardDevice.setTransport(new UsbTransport(device, usbManager));
|
||||
mSmartcardDevice.connectToDevice();
|
||||
|
||||
doNfcInBackground();
|
||||
}
|
||||
|
||||
public boolean isNfcConnected() {
|
||||
return mJavacardDevice.isConnected();
|
||||
return mSmartcardDevice.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -535,7 +533,7 @@ public abstract class BaseSecurityTokenNfcActivity extends BaseActivity
|
||||
|
||||
/**
|
||||
* Ask user if she wants to install PGP onto her Fidesmo token
|
||||
*/
|
||||
*/
|
||||
private void promptFidesmoPgpInstall() {
|
||||
FidesmoPgpInstallDialog fidesmoPgpInstallDialog = new FidesmoPgpInstallDialog();
|
||||
fidesmoPgpInstallDialog.show(getSupportFragmentManager(), "fidesmoPgpInstallDialog");
|
||||
@@ -552,6 +550,7 @@ public abstract class BaseSecurityTokenNfcActivity extends BaseActivity
|
||||
|
||||
/**
|
||||
* Use the package manager to detect if an application is installed on the phone
|
||||
*
|
||||
* @param uri an URI identifying the application's package
|
||||
* @return 'true' if the app is installed
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user