add installation for testing

This commit is contained in:
Michele Balistreri 2018-10-11 12:01:13 +02:00
parent 00057359ce
commit cb8c5c8e2b
6 changed files with 40 additions and 10 deletions

View File

@ -7,7 +7,7 @@ android {
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "0.0.2"
versionName "0.0.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {

View File

@ -10,7 +10,8 @@ import java.io.IOException;
public class CardManager extends Thread implements NfcAdapter.ReaderCallback {
public final static int ACTION_NONE = 0;
public final static int ACTION_INSTALL = 1;
public final static int ACTION_PERFTEST = 2;
public final static int ACTION_INSTALL_TEST = 2;
public final static int ACTION_PERFTEST = 3;
private NfcAdapter nfcAdapter;
private AssetManager assets;
@ -39,6 +40,9 @@ public class CardManager extends Thread implements NfcAdapter.ReaderCallback {
case ACTION_INSTALL:
Logger.i("installation requested");
break;
case ACTION_INSTALL_TEST:
Logger.i("installation with test secrets requested");
break;
case ACTION_PERFTEST:
Logger.i("performance tests requested");
break;
@ -115,7 +119,11 @@ public class CardManager extends Thread implements NfcAdapter.ReaderCallback {
switch (requestedAction) {
case ACTION_INSTALL:
Installer installer = new Installer(ch, this.assets, this.capPath);
Installer installer = new Installer(ch, this.assets, this.capPath, false);
installer.start();
break;
case ACTION_INSTALL_TEST:
installer = new Installer(ch, this.assets, this.capPath, true);
installer.start();
break;
case ACTION_PERFTEST:

View File

@ -17,15 +17,17 @@ public class Installer {
private Keys cardKeys;
private AssetManager assets;
private String capPath;
private boolean testSecrets;
static final byte[] cardKeyData = HexUtils.hexStringToByteArray("404142434445464748494a4b4c4d4e4f");
public Installer(Channel channel, AssetManager assets, String capPath) {
public Installer(Channel channel, AssetManager assets, String capPath, boolean testSecrets) {
this.plainChannel = channel;
this.channel = channel;
this.cardKeys = new Keys(cardKeyData, cardKeyData);
this.assets = assets;
this.capPath = capPath;
this.testSecrets = testSecrets;
}
public void start() throws IOException, APDUException, NoSuchAlgorithmException, InvalidKeySpecException {
@ -97,14 +99,15 @@ public class Installer {
}
private void installSecrets() throws NoSuchAlgorithmException, InvalidKeySpecException, APDUException, IOException {
Secrets secrets = Secrets.generate();
Logger.i(String.format("PIN: %s\nPUK: %s\nPairing password: %s\nPairing token: %s", secrets.getPin(), secrets.getPuk(), secrets.getPairingPassword(), HexUtils.byteArrayToHexString(secrets.getPairingToken())));
Secrets secrets = testSecrets ? Secrets.testSecrets() : Secrets.generate();
WalletAppletCommandSet cmdSet = new WalletAppletCommandSet((CardChannel) this.plainChannel);
byte[] ecKey = cmdSet.select().checkOK().getData();
SecureChannelSession secureChannel = new SecureChannelSession(Arrays.copyOfRange(ecKey, 2, ecKey.length));
cmdSet.setSecureChannel(secureChannel);
cmdSet.init(secrets.getPin(), secrets.getPuk(), secrets.getPairingToken()).checkOK();
Logger.i(String.format("PIN: %s\nPUK: %s\nPairing password: %s\nPairing token: %s", secrets.getPin(), secrets.getPuk(), secrets.getPairingPassword(), HexUtils.byteArrayToHexString(secrets.getPairingToken())));
}
private APDUResponse send(String description, APDUCommand cmd) throws IOException, APDUException {

View File

@ -22,6 +22,7 @@ public class MainActivity extends AppCompatActivity implements UILogger {
private ScrollView textViewScroll;
private Button buttonInstall;
private Button buttonInstallTest;
private Button buttonPerfTest;
private CardManager cardManager;
@ -48,6 +49,13 @@ public class MainActivity extends AppCompatActivity implements UILogger {
requestAction(CardManager.ACTION_INSTALL);
}
});
buttonInstallTest = (Button) findViewById(R.id.buttonInstallTest);
buttonInstallTest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
requestAction(CardManager.ACTION_INSTALL_TEST);
}
});
buttonPerfTest = (Button) findViewById(R.id.buttonPerfTest);
buttonPerfTest.setOnClickListener(new View.OnClickListener() {
@Override

View File

@ -30,6 +30,12 @@ public class Secrets {
return new Secrets(pin, puk, pairingPassword, pairingToken);
}
public static Secrets testSecrets() throws NoSuchAlgorithmException, InvalidKeySpecException {
String pairingPassword = "WalletAppletTest";
byte[] pairingToken = Crypto.generatePairingKey(pairingPassword.toCharArray());
return new Secrets("000000", "123456789012", pairingPassword, pairingToken);
}
public String getPin() {
return pin;
}

View File

@ -24,11 +24,16 @@
</ScrollView>
<Button
android:id="@+id/buttonInstall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Install" />
android:id="@+id/buttonInstall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Install Secure"/>
<Button
android:id="@+id/buttonInstallTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Install with test PIN/PUK"/>
<Button
android:id="@+id/buttonPerfTest"
android:layout_width="match_parent"