add ExternalAuthentication class and test
This commit is contained in:
parent
01af228057
commit
d6ca276c3f
|
@ -0,0 +1,29 @@
|
|||
package im.status.applet_installer_test.appletinstaller.apducommands;
|
||||
|
||||
import im.status.applet_installer_test.appletinstaller.Crypto;
|
||||
|
||||
public class ExternalAuthenticate {
|
||||
public static int CLA = 0x84;
|
||||
public static int INS = 0x82;
|
||||
public static int P1 = 0x01;
|
||||
public static int P2 = 0x00;
|
||||
|
||||
private byte[] encKeyData;
|
||||
private byte[] cardChallenge;
|
||||
private byte[] hostChallenge;
|
||||
|
||||
public ExternalAuthenticate(byte[] encKeyData, byte[] cardChallenge, byte[] hostChallenge) {
|
||||
this.encKeyData = encKeyData;
|
||||
this.cardChallenge = cardChallenge;
|
||||
this.hostChallenge = hostChallenge;
|
||||
}
|
||||
|
||||
public byte[] getHostCryptogram() {
|
||||
byte[] data = new byte[this.cardChallenge.length + this.hostChallenge.length];
|
||||
System.arraycopy(cardChallenge, 0, data, 0, cardChallenge.length);
|
||||
System.arraycopy(hostChallenge, 0, data, cardChallenge.length, hostChallenge.length);
|
||||
byte[] paddedData = Crypto.appendDESPadding(data);
|
||||
|
||||
return Crypto.mac3des(this.encKeyData, paddedData, Crypto.NullBytes8);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package im.status.applet_installer_test.appletinstaller.apducommands;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import im.status.applet_installer_test.appletinstaller.HexUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ExternalAuthenticateTest {
|
||||
@Test
|
||||
public void getHostCryptogram() {
|
||||
byte[] encKeyData = HexUtils.hexStringToByteArray("0EF72A1065236DD6CAC718D5E3F379A4");
|
||||
byte[] cardChallenge = HexUtils.hexStringToByteArray("0076a6c0d55e9535");
|
||||
byte[] hostChallenge = HexUtils.hexStringToByteArray("266195e638da1b95");
|
||||
|
||||
ExternalAuthenticate auth = new ExternalAuthenticate(encKeyData, cardChallenge, hostChallenge);
|
||||
|
||||
String expectedHostCryptogram = "45A5F48DAE68203C";
|
||||
byte[] hostCryptogram = auth.getHostCryptogram();
|
||||
assertEquals(expectedHostCryptogram, HexUtils.byteArrayToHexString(hostCryptogram));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue