Browse Source

IC Verification now checks 3 name fields for longest name for name checking

hbw_build
Wong Joon Hui 2 years ago
parent
commit
1afe6f206e
  1. 83
      app/src/main/java/com/cst/im30/activity/ICCActivity.java
  2. 90
      app/src/main/java/com/cst/im30/utility/NRICApduUtils.java

83
app/src/main/java/com/cst/im30/activity/ICCActivity.java

@ -23,6 +23,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.cst.im30.R;
import com.cst.im30.utility.IccTester;
import com.cst.im30.utility.Logger;
import com.cst.im30.utility.NRICApduUtils;
import java.io.BufferedWriter;
import java.io.File;
@ -387,52 +388,29 @@ public class ICCActivity extends AppCompatActivity {
IccTester.getInstance(getApplicationContext()).autoResp((byte) 0, true);// 设置iccIsoCommand函数是否自动发送GET RESPONSE指令。
byte[] selectJpn = new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x00, (byte) 0x0A, (byte) 0xA0, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x74, (byte) 0x4A, (byte) 0x50, (byte) 0x4E, (byte) 0x00, (byte) 0x10};
byte[] readIc = new byte[]{(byte) 0xC8, (byte) 0x32, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x0D, (byte) 0x00};
byte[] readIc1 = new byte[]{(byte) 0xCC, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x11, (byte) 0x01, (byte) 0x0D, (byte) 0x00};
byte[] readIc2 = new byte[]{(byte) 0xCC, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x0D};
byte[] readName = new byte[]{(byte) 0xC8, (byte) 0x32, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x28, (byte) 0x00};
byte[] readName1 = new byte[]{(byte) 0xCC, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0xE9, (byte) 0x00, (byte) 0x28, (byte) 0x00};
byte[] readName2 = new byte[]{(byte) 0xCC, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x28};
byte[] readCard = new byte[]{(byte) 0xC8, (byte) 0x32, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00};
byte[] readCard1 = new byte[]{(byte) 0xCC, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x8F, (byte) 0x01, (byte) 0x01, (byte) 0x00};
byte[] readCard2 = new byte[]{(byte) 0xCC, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x01};
byte[] isoRes = IccTester.getInstance(getApplicationContext()).isoCommand((byte) 0, selectJpn);
byte[] isoRes = NRICApduUtils.selectAppJPN(getApplicationContext());
if (isoRes != null) {
String isoStr = null;
try {
byte[] isoResx = IccTester.getInstance(getApplicationContext()).isoCommand((byte) 0, readIc);
byte[] isoRes1 = IccTester.getInstance(getApplicationContext()).isoCommand((byte) 0, readIc1);
Log.d("ZZZ1", getHexValue(isoRes1));
byte[] isoRes2 = IccTester.getInstance(getApplicationContext()).isoCommand((byte) 0, readIc2);
Log.d("ZZZ2", getHexValue(isoRes2));
byte[] icBytes = Arrays.copyOfRange(isoRes2, 0, isoRes2.length - 3);
Log.d("ZZZ3", new String(icBytes));
nric = NRICApduUtils.getIDNum(getApplicationContext());
nric = new String(icBytes);
String orgName = NRICApduUtils.getOriginalName(getApplicationContext());
String gmpcName = NRICApduUtils.getGMPCName(getApplicationContext());
String kptName = NRICApduUtils.getKPTName(getApplicationContext());
byte[] isoResN = IccTester.getInstance(getApplicationContext()).isoCommand((byte) 0, readName);
Log.d("ZZZ4", getHexValue(isoResN));
byte[] isoResN1 = IccTester.getInstance(getApplicationContext()).isoCommand((byte) 0, readName1);
Log.d("ZZZ5", getHexValue(isoResN1));
byte[] isoResN2 = IccTester.getInstance(getApplicationContext()).isoCommand((byte) 0, readName2);
Log.d("ZZZ6", getHexValue(isoResN2));
byte[] nameBytes = Arrays.copyOfRange(isoResN2, 0, isoResN2.length - 2);
Log.d("ZZZ7", new String(nameBytes));
name = new String(nameBytes);
String selectedName = orgName;
if (selectedName.length() < gmpcName.length()) {
selectedName = gmpcName;
}
if (selectedName.length() < kptName.length()) {
selectedName = kptName;
}
name = selectedName;
byte[] isoResC = IccTester.getInstance(getApplicationContext()).isoCommand((byte) 0, readCard);
Log.d("ZZZ8", getHexValue(isoResC));
@ -450,7 +428,6 @@ public class ICCActivity extends AppCompatActivity {
cardVer = new String(cardBytes);
nric += getHexValue(cardBytes);
//readData();
} catch (Exception e) {
ICCActivity.appendLog(e);
@ -475,8 +452,6 @@ public class ICCActivity extends AppCompatActivity {
handler.sendMessage(message);
}
SystemClock.sleep(500);
break;
} else {
//resString = getResources().getString(R.string.icc_detect_nocard);
Message message = Message.obtain();
@ -484,14 +459,16 @@ public class ICCActivity extends AppCompatActivity {
message.obj = "No card.";
handler.sendMessage(message);
SystemClock.sleep(500);
break;
}
SystemClock.sleep(500);
break;
}
IccTester.getInstance(ICCActivity.this).light(false);
}
}
public class CardDetectedThread extends Thread {
@Override
public void run() {
@ -502,23 +479,19 @@ public class ICCActivity extends AppCompatActivity {
while (!Thread.interrupted()) {
boolean detect = IccTester.getInstance(ICCActivity.this).detect((byte) 0);
Message message = Message.obtain();
if (detect) {
Message message = Message.obtain();
message.what = 0;
message.obj = "Remove card";
handlerCard.sendMessage(message);
SystemClock.sleep(500);
break;
} else {
Message message = Message.obtain();
message.what = 1;
message.obj = "No card";
handlerCard.sendMessage(message);
SystemClock.sleep(500);
break;
}
handlerCard.sendMessage(message);
SystemClock.sleep(500);
break;
}
IccTester.getInstance(ICCActivity.this).light(false);
@ -535,23 +508,19 @@ public class ICCActivity extends AppCompatActivity {
while (!Thread.interrupted()) {
boolean detect = IccTester.getInstance(ICCActivity.this).detect((byte) 0);
Message message = Message.obtain();
if (detect) {
Message message = Message.obtain();
message.what = 0;
message.obj = "Detect card";
handlerInsertCard.sendMessage(message);
SystemClock.sleep(500);
break;
} else {
Message message = Message.obtain();
message.what = 1;
message.obj = "No card";
handlerInsertCard.sendMessage(message);
SystemClock.sleep(500);
break;
}
handlerInsertCard.sendMessage(message);
SystemClock.sleep(500);
break;
}
IccTester.getInstance(ICCActivity.this).light(false);

90
app/src/main/java/com/cst/im30/utility/NRICApduUtils.java

@ -0,0 +1,90 @@
package com.cst.im30.utility;
import android.annotation.SuppressLint;
import android.content.Context;
import java.util.Arrays;
@SuppressWarnings({"unused"})
public class NRICApduUtils {
public static byte[] selectAppJPN(Context applicationContext) {
byte[] selectJpn = new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x00, (byte) 0x0A, (byte) 0xA0, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x74, (byte) 0x4A, (byte) 0x50, (byte) 0x4E, (byte) 0x00, (byte) 0x10};
Logger.logD("Select APP JPN");
return IccTester.getInstance(applicationContext).isoCommand((byte) 0, selectJpn);
}
public static String getOriginalName(Context applicationContext) {
byte[] setLengthByte = new byte[]{(byte) 0xC8, (byte) 0x32, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x96, (byte) 0x00};
byte[] selectInfoByte = new byte[]{(byte) 0xCC, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x96, (byte) 0x00};
byte[] readInfoByte = new byte[]{(byte) 0xCC, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x96};
byte[] setLengthByteResponse = IccTester.getInstance(applicationContext).isoCommand((byte) 0, setLengthByte);
byte[] selectInfoByteResponse = IccTester.getInstance(applicationContext).isoCommand((byte) 0, selectInfoByte);
byte[] readInfoByteResponse = IccTester.getInstance(applicationContext).isoCommand((byte) 0, readInfoByte);
byte[] trimmedBytes = Arrays.copyOfRange(readInfoByteResponse, 0, readInfoByteResponse.length - 3);
String str = new String(trimmedBytes).trim();
Logger.logD("JPN_OrgName:" + str);
return str;
}
public static String getGMPCName(Context applicationContext) {
byte[] setLengthByte = new byte[]{(byte) 0xC8, (byte) 0x32, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x50, (byte) 0x00};
byte[] selectInfoByte = new byte[]{(byte) 0xCC, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x99, (byte) 0x00, (byte) 0x50, (byte) 0x00};
byte[] readInfoByte = new byte[]{(byte) 0xCC, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x50};
byte[] setLengthByteResponse = IccTester.getInstance(applicationContext).isoCommand((byte) 0, setLengthByte);
byte[] selectInfoByteResponse = IccTester.getInstance(applicationContext).isoCommand((byte) 0, selectInfoByte);
byte[] readInfoByteResponse = IccTester.getInstance(applicationContext).isoCommand((byte) 0, readInfoByte);
byte[] trimmedBytes = Arrays.copyOfRange(readInfoByteResponse, 0, readInfoByteResponse.length - 3);
String str = new String(trimmedBytes).trim();
Logger.logD("JPN_GMPCName:" + str);
return str;
}
public static String getKPTName(Context applicationContext) {
byte[] setLengthByte = new byte[]{(byte) 0xC8, (byte) 0x32, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x28, (byte) 0x00};
byte[] selectInfoByte = new byte[]{(byte) 0xCC, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0xE9, (byte) 0x00, (byte) 0x28, (byte) 0x00};
byte[] readInfoByte = new byte[]{(byte) 0xCC, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x28};
byte[] setLengthByteResponse = IccTester.getInstance(applicationContext).isoCommand((byte) 0, setLengthByte);
byte[] selectInfoByteResponse = IccTester.getInstance(applicationContext).isoCommand((byte) 0, selectInfoByte);
byte[] readInfoByteResponse = IccTester.getInstance(applicationContext).isoCommand((byte) 0, readInfoByte);
byte[] trimmedBytes = Arrays.copyOfRange(readInfoByteResponse, 0, readInfoByteResponse.length - 3);
String str = new String(trimmedBytes).trim();
Logger.logD("JPN_KPTName:" + str);
return str;
}
public static String getIDNum(Context applicationContext) {
byte[] setLengthByte = new byte[]{(byte) 0xC8, (byte) 0x32, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x0D, (byte) 0x00};
byte[] selectInfoByte = new byte[]{(byte) 0xCC, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x11, (byte) 0x01, (byte) 0x0D, (byte) 0x00};
byte[] readInfoByte = new byte[]{(byte) 0xCC, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x0D};
byte[] setLengthByteResponse = IccTester.getInstance(applicationContext).isoCommand((byte) 0, setLengthByte);
byte[] selectInfoByteResponse = IccTester.getInstance(applicationContext).isoCommand((byte) 0, selectInfoByte);
byte[] readInfoByteResponse = IccTester.getInstance(applicationContext).isoCommand((byte) 0, readInfoByte);
byte[] trimmedBytes = Arrays.copyOfRange(readInfoByteResponse, 0, readInfoByteResponse.length - 3);
String str = new String(trimmedBytes).trim();
Logger.logD("JPN_IDNum:" + str);
return str;
}
}
Loading…
Cancel
Save