fix all tests for Ledger
This commit is contained in:
parent
734347a093
commit
993672565c
|
@ -49,7 +49,7 @@ dependencies {
|
||||||
testCompile(files("../jcardsim/jcardsim-3.0.5-SNAPSHOT.jar"))
|
testCompile(files("../jcardsim/jcardsim-3.0.5-SNAPSHOT.jar"))
|
||||||
testCompile('org.web3j:core:2.3.1')
|
testCompile('org.web3j:core:2.3.1')
|
||||||
testCompile('org.bitcoinj:bitcoinj-core:0.14.5')
|
testCompile('org.bitcoinj:bitcoinj-core:0.14.5')
|
||||||
testCompile('com.github.status-im.status-keycard-java:desktop:99dbb24')
|
testCompile('com.github.status-im.status-keycard-java:desktop:f603979')
|
||||||
testCompile('org.bouncycastle:bcprov-jdk15on:1.60')
|
testCompile('org.bouncycastle:bcprov-jdk15on:1.60')
|
||||||
testCompile("org.junit.jupiter:junit-jupiter-api:5.1.1")
|
testCompile("org.junit.jupiter:junit-jupiter-api:5.1.1")
|
||||||
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.1.1")
|
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.1.1")
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.licel.jcardsim.utils.AIDUtil;
|
||||||
import im.status.keycard.applet.*;
|
import im.status.keycard.applet.*;
|
||||||
import im.status.keycard.desktop.LedgerUSBManager;
|
import im.status.keycard.desktop.LedgerUSBManager;
|
||||||
import im.status.keycard.desktop.PCSCCardChannel;
|
import im.status.keycard.desktop.PCSCCardChannel;
|
||||||
|
import im.status.keycard.io.APDUCommand;
|
||||||
import im.status.keycard.io.APDUResponse;
|
import im.status.keycard.io.APDUResponse;
|
||||||
import im.status.keycard.io.CardListener;
|
import im.status.keycard.io.CardListener;
|
||||||
import javacard.framework.AID;
|
import javacard.framework.AID;
|
||||||
|
@ -28,8 +29,10 @@ import org.web3j.tx.Transfer;
|
||||||
import org.web3j.utils.Convert;
|
import org.web3j.utils.Convert;
|
||||||
import org.web3j.utils.Numeric;
|
import org.web3j.utils.Numeric;
|
||||||
|
|
||||||
|
import javax.crypto.SecretKey;
|
||||||
|
import javax.crypto.SecretKeyFactory;
|
||||||
|
import javax.crypto.spec.PBEKeySpec;
|
||||||
import javax.smartcardio.*;
|
import javax.smartcardio.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -83,6 +86,19 @@ public class KeycardTest {
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unknown target");
|
throw new RuntimeException("Unknown target");
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
im.status.keycard.globalplatform.Crypto.addBouncyCastleProvider();
|
||||||
|
SecretKey key;
|
||||||
|
|
||||||
|
try {
|
||||||
|
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256", "BC");
|
||||||
|
PBEKeySpec spec = new PBEKeySpec("331345".toCharArray(), "Keycard Pairing Password Salt".getBytes(), 256, 32 * 8);
|
||||||
|
key = skf.generateSecret(spec);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Is Bouncycastle correctly initialized?");
|
||||||
|
}
|
||||||
|
|
||||||
|
SHARED_SECRET = key.getEncoded();*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
|
@ -188,7 +204,6 @@ public class KeycardTest {
|
||||||
secureChannel = new TestSecureChannelSession();
|
secureChannel = new TestSecureChannelSession();
|
||||||
cmdSet.setSecureChannel(secureChannel);
|
cmdSet.setSecureChannel(secureChannel);
|
||||||
cmdSet.select().checkOK();
|
cmdSet.select().checkOK();
|
||||||
cmdSet.setSecureChannel(secureChannel);
|
|
||||||
|
|
||||||
if (cmdSet.getApplicationInfo().hasSecureChannelCapability()) {
|
if (cmdSet.getApplicationInfo().hasSecureChannelCapability()) {
|
||||||
cmdSet.autoPair(SHARED_SECRET);
|
cmdSet.autoPair(SHARED_SECRET);
|
||||||
|
@ -222,14 +237,7 @@ public class KeycardTest {
|
||||||
APDUResponse response = cmdSet.select();
|
APDUResponse response = cmdSet.select();
|
||||||
assertEquals(0x9000, response.getSw());
|
assertEquals(0x9000, response.getSw());
|
||||||
byte[] data = response.getData();
|
byte[] data = response.getData();
|
||||||
assertEquals(KeycardApplet.TLV_APPLICATION_INFO_TEMPLATE, data[0]);
|
assertTrue(new ApplicationInfo(data).isInitializedCard());
|
||||||
assertEquals(KeycardApplet.TLV_UID, data[2]);
|
|
||||||
assertEquals(KeycardApplet.TLV_PUB_KEY, data[20]);
|
|
||||||
assertEquals(KeycardApplet.TLV_INT, data[22 + data[21]]);
|
|
||||||
assertEquals(KeycardApplet.APPLICATION_VERSION >> 8, data[24 + data[21]]);
|
|
||||||
assertEquals(KeycardApplet.APPLICATION_VERSION & 0xFF, data[25 + data[21]]);
|
|
||||||
assertEquals(KeycardApplet.TLV_INT, data[26 + data[21]]);
|
|
||||||
assertEquals(KeycardApplet.TLV_KEY_UID, data[29 + data[21]]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -304,8 +312,8 @@ public class KeycardTest {
|
||||||
response = cmdSet.openSecureChannel(secureChannel.getPairingIndex(), secureChannel.getPublicKey());
|
response = cmdSet.openSecureChannel(secureChannel.getPairingIndex(), secureChannel.getPublicKey());
|
||||||
assertEquals(0x9000, response.getSw());
|
assertEquals(0x9000, response.getSw());
|
||||||
secureChannel.processOpenSecureChannelResponse(response);
|
secureChannel.processOpenSecureChannelResponse(response);
|
||||||
ResponseAPDU resp2 = apduChannel.transmit(new CommandAPDU(0x80, SecureChannel.INS_MUTUALLY_AUTHENTICATE, 0, 0, new byte[48]));
|
APDUResponse resp2 = sdkChannel.send(new APDUCommand(0x80, SecureChannel.INS_MUTUALLY_AUTHENTICATE, 0, 0, new byte[48]));
|
||||||
assertEquals(0x6982, resp2.getSW());
|
assertEquals(0x6982, resp2.getSw());
|
||||||
secureChannel.reset();
|
secureChannel.reset();
|
||||||
response = cmdSet.mutuallyAuthenticate();
|
response = cmdSet.mutuallyAuthenticate();
|
||||||
assertEquals(0x6985, response.getSw());
|
assertEquals(0x6985, response.getSw());
|
||||||
|
@ -356,10 +364,9 @@ public class KeycardTest {
|
||||||
// Open secure channel
|
// Open secure channel
|
||||||
cmdSet.autoOpenSecureChannel();
|
cmdSet.autoOpenSecureChannel();
|
||||||
response = cmdSet.pair(SecureChannel.PAIR_P1_FIRST_STEP, challenge);
|
response = cmdSet.pair(SecureChannel.PAIR_P1_FIRST_STEP, challenge);
|
||||||
assertEquals(0x6985, response.getSw());
|
assertTrue((0x6985 == response.getSw()) || (0x6982 == response.getSw()));
|
||||||
cmdSet.openSecureChannel(secureChannel.getPairingIndex(), secureChannel.getPublicKey());
|
cmdSet.openSecureChannel(secureChannel.getPairingIndex(), secureChannel.getPublicKey());
|
||||||
|
|
||||||
|
|
||||||
// Pair multiple indexes
|
// Pair multiple indexes
|
||||||
for (int i = 1; i < 5; i++) {
|
for (int i = 1; i < 5; i++) {
|
||||||
cmdSet.autoPair(SHARED_SECRET);
|
cmdSet.autoPair(SHARED_SECRET);
|
||||||
|
@ -374,8 +381,11 @@ public class KeycardTest {
|
||||||
|
|
||||||
// Unpair all (except the last, which will be unpaired in the tearDown phase)
|
// Unpair all (except the last, which will be unpaired in the tearDown phase)
|
||||||
cmdSet.autoOpenSecureChannel();
|
cmdSet.autoOpenSecureChannel();
|
||||||
|
|
||||||
|
if (cmdSet.getApplicationInfo().hasCredentialsManagementCapability()) {
|
||||||
response = cmdSet.verifyPIN("000000");
|
response = cmdSet.verifyPIN("000000");
|
||||||
assertEquals(0x9000, response.getSw());
|
assertEquals(0x9000, response.getSw());
|
||||||
|
}
|
||||||
|
|
||||||
for (byte i = 0; i < 4; i++) {
|
for (byte i = 0; i < 4; i++) {
|
||||||
response = cmdSet.unpair(i);
|
response = cmdSet.unpair(i);
|
||||||
|
@ -401,12 +411,16 @@ public class KeycardTest {
|
||||||
|
|
||||||
// Not authenticated
|
// Not authenticated
|
||||||
cmdSet.autoOpenSecureChannel();
|
cmdSet.autoOpenSecureChannel();
|
||||||
|
|
||||||
|
if (cmdSet.getApplicationInfo().hasCredentialsManagementCapability()) {
|
||||||
response = cmdSet.unpair(sparePairingIndex);
|
response = cmdSet.unpair(sparePairingIndex);
|
||||||
assertEquals(0x6985, response.getSw());
|
assertEquals(0x6985, response.getSw());
|
||||||
|
|
||||||
// Wrong P1
|
|
||||||
response = cmdSet.verifyPIN("000000");
|
response = cmdSet.verifyPIN("000000");
|
||||||
assertEquals(0x9000, response.getSw());
|
assertEquals(0x9000, response.getSw());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrong P1
|
||||||
response = cmdSet.unpair((byte) 5);
|
response = cmdSet.unpair((byte) 5);
|
||||||
assertEquals(0x6A86, response.getSw());
|
assertEquals(0x6A86, response.getSw());
|
||||||
|
|
||||||
|
@ -1307,7 +1321,7 @@ public class KeycardTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Sign actual Ethereum transaction")
|
@DisplayName("Sign actual Ethereum transaction")
|
||||||
@Capabilities("manual")
|
@Tag("manual")
|
||||||
void signTransactionTest() throws Exception {
|
void signTransactionTest() throws Exception {
|
||||||
// Initialize credentials
|
// Initialize credentials
|
||||||
Web3j web3j = Web3j.build(new HttpService());
|
Web3j web3j = Web3j.build(new HttpService());
|
||||||
|
|
Loading…
Reference in New Issue