Compare commits

Author SHA1 Message Date
Michele Balistreri d3eb43b8e5 revert jdk change 2018-10-16 12:11:32 +02:00
Michele Balistreri e2afb066c3 bump version name to match next GitHub release 2018-10-16 12:09:12 +02:00
Michele Balistreri 0272fadb85 add installation/deletion of NDEF applet 2018-10-16 12:06:55 +02:00
Michele Balistreri cb8c5c8e2b add installation for testing 2018-10-11 12:01:13 +02:00
Bitgamma 00057359ce Merge pull request #2 from status-im/no-inst-params
support secret personalization separate from INSTALL command
2018-10-10 19:49:41 +03:00
6 changed files with 56 additions and 22 deletions
+2 -2
View File
@@ -6,8 +6,8 @@ android {
applicationId "im.status.applet_installer_test.appletinstaller"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "0.0.2"
versionCode 5
versionName "0.0.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
@@ -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:
@@ -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 {
@@ -56,20 +58,26 @@ public class Installer {
//Status status = new Status(Status.P1_EXECUTABLE_LOAD_FILES_AND_MODULES);
//resp = this.send("status", status.getCommand());
byte[] aid = HexUtils.hexStringToByteArray("53746174757357616C6C6574");
byte[] appletAID = HexUtils.hexStringToByteArray("53746174757357616C6C6574417070");
byte[] packageAID = HexUtils.hexStringToByteArray("53746174757357616C6C6574");
byte[] walletAID = HexUtils.hexStringToByteArray("53746174757357616C6C6574417070");
byte[] ndefAppletAID = HexUtils.hexStringToByteArray("53746174757357616C6C65744E4643");
byte[] ndefInstanceAID = HexUtils.hexStringToByteArray("D2760000850101");
Delete deleteApplet = new Delete(appletAID);
Delete deleteNDEFApplet = new Delete(ndefInstanceAID);
Logger.i("sending delete (NDEF applet)");
this.channel.send(deleteNDEFApplet.getCommand());
Delete deleteApplet = new Delete(walletAID);
Logger.i("sending delete (applet)");
this.channel.send(deleteApplet.getCommand());
Delete deletePkg = new Delete(aid);
Delete deletePkg = new Delete(packageAID);
Logger.i("sending delete (pkg)");
this.channel.send(deletePkg.getCommand());
InstallForLoad preLoad = new InstallForLoad(aid, sdaid);
InstallForLoad preLoad = new InstallForLoad(packageAID, sdaid);
this.send("perform for load", preLoad.getCommand());
@@ -82,13 +90,11 @@ public class Installer {
this.send("load " + load.getCount() + "/37", loadCmd);
}
InstallForInstall installNDEF = new InstallForInstall(packageAID, ndefAppletAID, ndefInstanceAID, new byte[0]);
this.send("perform and make selectable (NDEF)", installNDEF.getCommand());
byte[] packageAID = HexUtils.hexStringToByteArray("53746174757357616C6C6574");
byte[] instanceAID = HexUtils.hexStringToByteArray("53746174757357616C6C6574417070");
InstallForInstall install = new InstallForInstall(packageAID, appletAID, instanceAID, new byte[0]);
this.send("perform and make selectable", install.getCommand());
InstallForInstall install = new InstallForInstall(packageAID, walletAID, walletAID, new byte[0]);
this.send("perform and make selectable (wallet)", install.getCommand());
installSecrets();
@@ -97,14 +103,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 {
@@ -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
@@ -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;
}
+9 -4
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"