test GET DATA + STORE DATA

This commit is contained in:
Michele Balistreri 2019-04-09 12:56:54 +03:00
parent 7edee9c594
commit 3e49fe9626
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
3 changed files with 65 additions and 3 deletions

View File

@ -30,7 +30,7 @@ javacard {
className = 'NDEFApplet'
}
version = '2.2'
version = '2.3'
}
}
@ -54,7 +54,7 @@ dependencies {
testCompile(files("../jcardsim/jcardsim-3.0.5-SNAPSHOT.jar"))
testCompile('org.web3j:core:2.3.1')
testCompile('org.bitcoinj:bitcoinj-core:0.14.5')
testCompile('com.github.status-im.status-keycard-java:desktop:2.2.1')
testCompile('com.github.status-im.status-keycard-java:desktop:5771994')
testCompile('org.bouncycastle:bcprov-jdk15on:1.60')
testCompile("org.junit.jupiter:junit-jupiter-api:5.1.1")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.1.1")

View File

@ -8,7 +8,7 @@ import javacardx.crypto.Cipher;
* The applet's main class. All incoming commands a processed by this class.
*/
public class KeycardApplet extends Applet {
static final short APPLICATION_VERSION = (short) 0x0202;
static final short APPLICATION_VERSION = (short) 0x0203;
static final byte INS_GET_STATUS = (byte) 0xF2;
static final byte INS_SET_NDEF = (byte) 0xF3;

View File

@ -1263,6 +1263,68 @@ public class KeycardTest {
assertEquals(0x9000, response.getSw());
}
@Test
@DisplayName("STORE/GET DATA")
void storeGetData() throws Exception {
APDUResponse response;
if (cmdSet.getApplicationInfo().hasSecureChannelCapability()) {
// Security condition violation: SecureChannel not open
response = cmdSet.storePublicData(new byte[20]);
assertEquals(0x6985, response.getSw());
cmdSet.autoOpenSecureChannel();
}
if (cmdSet.getApplicationInfo().hasCredentialsManagementCapability()) {
// Security condition violation: PIN not verified
response = cmdSet.storePublicData(new byte[20]);
assertEquals(0x6985, response.getSw());
response = cmdSet.verifyPIN("000000");
assertEquals(0x9000, response.getSw());
}
// Data too long
response = cmdSet.storePublicData(new byte[128]);
assertEquals(0x6A80, response.getSw());
byte[] data = new byte[127];
for (int i = 0; i < 127; i++) {
data[i] = (byte) i;
}
// Correct data
response = cmdSet.storePublicData(data);
assertEquals(0x9000, response.getSw());
// Read data back with secure channel
response = cmdSet.getPublicData();
assertEquals(0x9000, response.getSw());
assertArrayEquals(data, response.getData());
// Empty data
response = cmdSet.storePublicData(new byte[0]);
assertEquals(0x9000, response.getSw());
response = cmdSet.getPublicData();
assertEquals(0x9000, response.getSw());
assertEquals(0, response.getData().length);
// Shorter data
data = Arrays.copyOf(data, 20);
response = cmdSet.storePublicData(data);
assertEquals(0x9000, response.getSw());
// GET DATA without Secure Channel
cmdSet.select().checkOK();
response = cmdSet.getPublicData();
assertEquals(0x9000, response.getSw());
assertArrayEquals(data, response.getData());
}
@Test
@DisplayName("DUPLICATE KEY command")
@Capabilities("keyManagement")