integrate performance tests back in the code
This commit is contained in:
parent
c86ca40480
commit
969c33aa20
|
@ -1,26 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="5">
|
||||
<list size="9">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
|
||||
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
|
||||
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
|
||||
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="4">
|
||||
<list size="9">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||
<item index="4" class="java.lang.String" itemvalue="javax.validation.constraints.NotNull" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
|
||||
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
|
||||
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
|
||||
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -8,27 +8,46 @@ import android.nfc.tech.IsoDep;
|
|||
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;
|
||||
|
||||
private NfcAdapter nfcAdapter;
|
||||
private AssetManager assets;
|
||||
private String capPath;
|
||||
private IsoDep isoDep;
|
||||
private boolean installationRequested;
|
||||
private int requestedAction;
|
||||
private long cardConnectedAt;
|
||||
private boolean installing;
|
||||
private boolean running;
|
||||
|
||||
public CardManager(NfcAdapter nfcAdapter, AssetManager assets, String capPath) {
|
||||
this.nfcAdapter = nfcAdapter;
|
||||
this.assets = assets;
|
||||
this.capPath = capPath;
|
||||
this.requestedAction = ACTION_NONE;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return this.isoDep != null && this.isoDep.isConnected();
|
||||
}
|
||||
|
||||
public void startInstallation() {
|
||||
public void requestAction(int actionRequested) {
|
||||
switch(actionRequested) {
|
||||
case ACTION_NONE:
|
||||
Logger.log("cancelling requested action");
|
||||
break;
|
||||
case ACTION_INSTALL:
|
||||
Logger.log("installation requested");
|
||||
this.installationRequested = true;
|
||||
break;
|
||||
case ACTION_PERFTEST:
|
||||
Logger.log("performance tests requested");
|
||||
break;
|
||||
default:
|
||||
Logger.log("invalid action requested, ignoring");
|
||||
return;
|
||||
}
|
||||
|
||||
this.requestedAction = actionRequested;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,10 +77,10 @@ public class CardManager extends Thread implements NfcAdapter.ReaderCallback {
|
|||
}
|
||||
}
|
||||
|
||||
if (connected && this.installationRequested && !this.installing) {
|
||||
if (connected && (this.requestedAction != ACTION_NONE) && !this.running) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - this.cardConnectedAt > 2000) {
|
||||
this.install();
|
||||
this.perform();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,10 +95,10 @@ public class CardManager extends Thread implements NfcAdapter.ReaderCallback {
|
|||
|
||||
private void onCardConnected() {
|
||||
this.cardConnectedAt = System.currentTimeMillis();
|
||||
if (this.installationRequested) {
|
||||
Logger.log("waiting 2 seconds to start installation");
|
||||
if (this.requestedAction != ACTION_NONE) {
|
||||
Logger.log("waiting 2 seconds to start requested action");
|
||||
} else {
|
||||
Logger.log("installation not requested yet");
|
||||
Logger.log("no action requested yet");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,20 +107,34 @@ public class CardManager extends Thread implements NfcAdapter.ReaderCallback {
|
|||
this.isoDep = null;
|
||||
}
|
||||
|
||||
public void install() {
|
||||
Logger.log("starting installation");
|
||||
this.installing = true;
|
||||
private void perform() {
|
||||
Logger.log("starting requested action");
|
||||
this.running = true;
|
||||
try {
|
||||
CardChannel ch = new CardChannel(this.isoDep);
|
||||
|
||||
switch (requestedAction) {
|
||||
case ACTION_INSTALL:
|
||||
Installer installer = new Installer(ch, this.assets, this.capPath);
|
||||
installer.start();
|
||||
break;
|
||||
case ACTION_PERFTEST:
|
||||
PerfTest perfTest = new PerfTest(ch);
|
||||
perfTest.test();
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unknown action");
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
Logger.log("IO exception: " + e.getMessage());
|
||||
} catch (APDUException e) {
|
||||
Logger.log("APDU exception: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
Logger.log("Other exception: " + e.getMessage());
|
||||
} finally {
|
||||
this.installing = false;
|
||||
this.installationRequested = false;
|
||||
this.running = false;
|
||||
this.requestedAction = ACTION_NONE;
|
||||
this.cardConnectedAt = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class Installer {
|
|||
|
||||
|
||||
InstallForLoad preLoad = new InstallForLoad(aid, sdaid);
|
||||
this.send("install for load", preLoad.getCommand());
|
||||
this.send("perform for load", preLoad.getCommand());
|
||||
|
||||
|
||||
//URL url = this.getClass().getClassLoader().getResource("wallet.cap");
|
||||
|
@ -85,7 +85,7 @@ public class Installer {
|
|||
|
||||
byte[] params = HexUtils.hexStringToByteArray("3236393732333032383339318bfb5c8ea8b78a84b9efbfbc897d80312e71e559145947f447d8b6d0d9fcdb55");
|
||||
InstallForInstall install = new InstallForInstall(packageAID, appletAID, instanceAID, params);
|
||||
this.send("install and make selectable", install.getCommand());
|
||||
this.send("perform and make selectable", install.getCommand());
|
||||
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
Logger.log(String.format("installation completed in %d seconds", duration / 1000));
|
||||
|
|
|
@ -8,17 +8,22 @@ interface UILogger {
|
|||
|
||||
public class Logger {
|
||||
private static UILogger uiLogger;
|
||||
private static boolean mute;
|
||||
|
||||
public static void setUILogger(UILogger l) {
|
||||
uiLogger = l;
|
||||
}
|
||||
|
||||
public static void setMute(boolean m) {
|
||||
mute = m;
|
||||
}
|
||||
|
||||
public static void log(String m) {
|
||||
log(m, true);
|
||||
}
|
||||
|
||||
public static void log(String m, boolean showInUI) {
|
||||
if (m != null) {
|
||||
if (!mute && m != null) {
|
||||
Log.d("installer-debug", m);
|
||||
if (showInUI && uiLogger != null) {
|
||||
uiLogger.log(m);
|
||||
|
|
|
@ -4,13 +4,11 @@ import android.content.res.AssetManager;
|
|||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.nfc.NfcAdapter;
|
||||
import android.nfc.Tag;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
import java.io.IOException;
|
||||
import java.security.Security;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements UILogger {
|
||||
|
@ -24,8 +22,6 @@ public class MainActivity extends AppCompatActivity implements UILogger {
|
|||
|
||||
private Button buttonInstall;
|
||||
private Button buttonPerfTest;
|
||||
private Tag tag;
|
||||
private boolean installationAttempted;
|
||||
private CardManager cardManager;
|
||||
|
||||
@Override
|
||||
|
@ -44,31 +40,17 @@ public class MainActivity extends AppCompatActivity implements UILogger {
|
|||
textView = (TextView) findViewById(R.id.textView);
|
||||
textView.setMovementMethod(new ScrollingMovementMethod());
|
||||
buttonInstall = (Button) findViewById(R.id.buttonInstall);
|
||||
buttonInstall.setEnabled(true);
|
||||
buttonInstall.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//disableButtons();
|
||||
try {
|
||||
install();
|
||||
} catch (APDUException e) {
|
||||
logException(e);
|
||||
} catch (IOException e) {
|
||||
logException(e);
|
||||
}
|
||||
requestAction(CardManager.ACTION_INSTALL);
|
||||
}
|
||||
});
|
||||
buttonPerfTest = (Button) findViewById(R.id.buttonPerfTest);
|
||||
buttonPerfTest.setEnabled(false);
|
||||
buttonPerfTest.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
disableButtons();
|
||||
try {
|
||||
perfTest();
|
||||
} catch (Exception e) {
|
||||
Logger.log(e.getMessage());
|
||||
}
|
||||
requestAction(CardManager.ACTION_PERFTEST);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -82,20 +64,13 @@ public class MainActivity extends AppCompatActivity implements UILogger {
|
|||
Logger.log("exception: " + msg);
|
||||
}
|
||||
|
||||
public void install() throws IOException, APDUException {
|
||||
private void requestAction(int action) {
|
||||
if (this.cardManager != null) {
|
||||
clearTextView();
|
||||
this.cardManager.startInstallation();
|
||||
this.cardManager.requestAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
public void perfTest() throws Exception {
|
||||
Logger.log("Starting performance tests");
|
||||
PerfTest pf = new PerfTest(tag);
|
||||
pf.connect();
|
||||
pf.test();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
@ -115,31 +90,6 @@ public class MainActivity extends AppCompatActivity implements UILogger {
|
|||
}
|
||||
}
|
||||
|
||||
private void start(Tag tag) throws IOException {
|
||||
this.tag = tag;
|
||||
this.enableButtons();
|
||||
}
|
||||
|
||||
public void enableButtons() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
buttonInstall.setEnabled(true);
|
||||
buttonPerfTest.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void disableButtons() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
buttonInstall.setEnabled(false);
|
||||
buttonPerfTest.setEnabled(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void log(final String s) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -26,8 +26,7 @@ import java.util.Arrays;
|
|||
import java.util.Random;
|
||||
|
||||
public class PerfTest {
|
||||
private Tag tag;
|
||||
private IsoDep isoDep;
|
||||
private CardChannel cardChannel;
|
||||
private WalletAppletCommandSet cmdSet;
|
||||
private SecureChannelSession secureChannel;
|
||||
|
||||
|
@ -52,19 +51,12 @@ public class PerfTest {
|
|||
public static final byte[] SHARED_SECRET = new byte[] { (byte) 0x17, (byte) 0x83, (byte) 0x81, (byte) 0xc5, (byte) 0xe8, (byte) 0xd3, (byte) 0x24, (byte) 0xbe, (byte) 0xd4, (byte) 0x03, (byte) 0x3d, (byte) 0x14, (byte) 0xe1, (byte) 0xe1, (byte) 0xfd, (byte) 0xca, (byte) 0xaa, (byte) 0xdb, (byte) 0x74, (byte) 0x80, (byte) 0x38, (byte) 0x69, (byte) 0xbe, (byte) 0xe9, (byte) 0xf7, (byte) 0xa1, (byte) 0x0b, (byte) 0x1b, (byte) 0x71, (byte) 0x08, (byte) 0xed, (byte) 0x53 };
|
||||
|
||||
|
||||
public PerfTest(Tag tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public void connect() throws IOException {
|
||||
this.isoDep = IsoDep.get(tag);
|
||||
this.isoDep.setTimeout(10000);
|
||||
this.isoDep.connect();
|
||||
public PerfTest(CardChannel cardChannel) {
|
||||
this.cardChannel = cardChannel;
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
CardChannel apduChannel = new CardChannel(this.isoDep);
|
||||
cmdSet = new WalletAppletCommandSet(apduChannel);
|
||||
cmdSet = new WalletAppletCommandSet(cardChannel);
|
||||
byte[] keyData = extractPublicKeyFromSelect(cmdSet.select().getData());
|
||||
secureChannel = new SecureChannelSession(keyData);
|
||||
cmdSet.setSecureChannel(secureChannel);
|
||||
|
@ -72,8 +64,13 @@ public class PerfTest {
|
|||
cmdSet.autoOpenSecureChannel();
|
||||
cmdSet.verifyPIN("000000").checkOK();
|
||||
cmdSet.unpairOthers(); // Recover in case of non-clean termination
|
||||
Logger.log("Measuring performances. APDU logging disabled");
|
||||
Logger.log("*********************************************");
|
||||
Logger.setMute(true);
|
||||
loadKeys();
|
||||
Logger.setMute(true);
|
||||
measureLogin();
|
||||
Logger.log("*********************************************");
|
||||
cmdSet.select();
|
||||
cmdSet.autoOpenSecureChannel();
|
||||
cmdSet.verifyPIN("000000").checkOK();
|
||||
|
@ -92,6 +89,7 @@ public class PerfTest {
|
|||
cmdSet.deriveKey(derivePublicKey(resp.getData()), DERIVE_P1_SOURCE_CURRENT, true, true).checkOK();
|
||||
cmdSet.exportKey(EXPORT_KEY_P1_DATABASE, false).checkOK();
|
||||
time = System.currentTimeMillis() - time;
|
||||
Logger.setMute(false);
|
||||
Logger.log("Total login time: " + time + "ms");
|
||||
}
|
||||
|
||||
|
@ -109,7 +107,7 @@ public class PerfTest {
|
|||
cmdSet.deriveKey(derivePublicKey(resp.getData()), DERIVE_P1_SOURCE_CURRENT, true, true).checkOK();
|
||||
}
|
||||
time = System.currentTimeMillis() - time;
|
||||
|
||||
Logger.setMute(false);
|
||||
Logger.log("Total time for m/44'/60'/0'/0/0 derivation: " + time + "ms");
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ public class InstallForInstall {
|
|||
data.write(fullParams.length);
|
||||
data.write(fullParams);
|
||||
|
||||
// empty install token
|
||||
// empty perform token
|
||||
data.write(0x00);
|
||||
|
||||
return new APDUCommand(CLA, INS, P1, P2, data.toByteArray() );
|
||||
|
|
Loading…
Reference in New Issue