add ExternalAuthentication class and test

This commit is contained in:
Andrea Franz 2018-08-28 12:18:23 +02:00
parent 01af228057
commit d6ca276c3f
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
2 changed files with 52 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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));
}
}