Merge pull request #31 from status-im/unified-sdk

Unified sdk
This commit is contained in:
Bitgamma 2018-12-11 12:03:05 +03:00 committed by GitHub
commit 73b73ffa3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 326 additions and 271 deletions

View File

@ -41,8 +41,8 @@ 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("org.bouncycastle:bcprov-jdk15on:1.58")
testCompile("com.github.status-im:status-keycard-desktop:42086f6")
testCompile('com.github.status-im.status-keycard-java:desktop:2.0rc1')
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")
}

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,15 @@
package im.status.keycard;
import im.status.keycard.applet.ApplicationStatus;
import im.status.keycard.applet.KeycardCommandSet;
import im.status.keycard.io.APDUResponse;
import im.status.keycard.io.CardChannel;
import org.web3j.crypto.ECKeyPair;
import javax.smartcardio.CardChannel;
import javax.smartcardio.CardException;
import javax.smartcardio.ResponseAPDU;
import java.io.IOException;
import java.security.PrivateKey;
import java.security.interfaces.ECPrivateKey;
public class TestKeycardCommandSet extends KeycardCommandSet {
public TestKeycardCommandSet(CardChannel apduChannel) {
@ -23,9 +28,9 @@ public class TestKeycardCommandSet extends KeycardCommandSet {
*
* @param ecKeyPair a key pair
* @return the raw card response
* @throws CardException communication error
* @throws IOException communication error
*/
public ResponseAPDU loadKey(ECKeyPair ecKeyPair) throws CardException {
public APDUResponse loadKey(ECKeyPair ecKeyPair) throws IOException {
byte[] publicKey = ecKeyPair.getPublicKey().toByteArray();
byte[] privateKey = ecKeyPair.getPrivateKey().toByteArray();
@ -43,5 +48,45 @@ public class TestKeycardCommandSet extends KeycardCommandSet {
return loadKey(ansiPublic, privateKey, null);
}
/**
* Sends a LOAD KEY APDU. The given private key and chain code are formatted as a raw binary seed and the P1 of
* the command is set to LOAD_KEY_P1_SEED (0x03). This works on cards which support public key derivation.
* The loaded keyset is extended and support further key derivation.
*
* @param aPrivate a private key
* @param chainCode the chain code
* @return the raw card response
* @throws IOException communication error
*/
public APDUResponse loadKey(PrivateKey aPrivate, byte[] chainCode) throws IOException {
byte[] privateKey = ((ECPrivateKey) aPrivate).getS().toByteArray();
int privLen = privateKey.length;
int privOff = 0;
if(privateKey[0] == 0x00) {
privOff++;
privLen--;
}
byte[] data = new byte[chainCode.length + privLen];
System.arraycopy(privateKey, privOff, data, 0, privLen);
System.arraycopy(chainCode, 0, data, privLen, chainCode.length);
return loadKey(data, LOAD_KEY_P1_SEED);
}
/**
* Sends a GET STATUS APDU to retrieve the APPLICATION STATUS template and reads the byte indicating key initialization
* status
*
* @return whether the master key is present or not
* @throws IOException communication error
*/
public boolean getKeyInitializationStatus() throws IOException {
APDUResponse resp = getStatus(GET_STATUS_P1_APPLICATION);
return new ApplicationStatus(resp.getData()).hasMasterKey();
}
}

View File

@ -1,7 +1,13 @@
package im.status.keycard;
import im.status.keycard.applet.SecureChannelSession;
public class TestSecureChannelSession extends SecureChannelSession {
public void setOpen() {
super.setOpen();
}
public byte getPairingIndex() {
return getPairing().getPairingIndex();
}
}