Exemplo n.º 1
0
  private String getIdNumber() throws Exception {
    ResponseAPDU response;

    response =
        channel.transmit(
            new CommandAPDU(
                new byte[] {
                  0x00,
                  (byte) 0xA4,
                  0x04,
                  0x00,
                  0x0C,
                  (byte) 0xA0,
                  0x00,
                  0x00,
                  0x02,
                  0x43,
                  0x00,
                  0x13,
                  0x00,
                  0x00,
                  0x00,
                  0x01,
                  0x01
                }));
    if (response.getSW1() != 0x61) throw new Exception("Failed");

    response =
        channel.transmit(
            new CommandAPDU(new byte[] {0x00, (byte) 0xC0, 0x00, 0x00, (byte) response.getSW2()}));

    // select file
    response =
        channel.transmit(
            new CommandAPDU(new byte[] {0x00, (byte) 0xA4, 0x00, 0x00, 0x02, 0x02, 0x01}));
    if (response.getSW1() != 0x61) throw new Exception("Failed");

    // Get data--
    response =
        channel.transmit(
            new CommandAPDU(new byte[] {0x00, (byte) 0xC0, 0x00, 0x00, (byte) response.getSW2()}));

    // Read Binary B0
    response = channel.transmit(new CommandAPDU(new byte[] {0x00, (byte) 0xB0, 0x00, 0x00}));

    response =
        channel.transmit(
            new CommandAPDU(new byte[] {0x00, (byte) 0xB0, 0x00, 0x00, (byte) response.getSW2()}));
    if (response.getSW() != 0x9000) throw new Exception("Failed to read Id Number");
    int len = response.getData()[7];
    byte[] idBytes = new byte[len];
    System.arraycopy(response.getData(), 8, idBytes, 0, len);
    String result = "";
    for (int i = 0; i < idBytes.length; i++) {
      result += Character.toString((char) idBytes[i]);
    }
    ;
    return result.toString();
  }
Exemplo n.º 2
0
  private byte[] getProperty1() throws Exception {
    // -------------------------------------------------------------------------------
    // Select File & get data (Need analysis)
    // ------------------------------------------------------------------------------
    ResponseAPDU response;
    response =
        channel.transmit(
            new CommandAPDU(
                new byte[] {
                  0x00,
                  (byte) 0xA4,
                  0x04,
                  0x00,
                  0x0C,
                  (byte) 0xA0,
                  0x00,
                  0x00,
                  0x02,
                  0x43,
                  0x00,
                  0x13,
                  0x00,
                  0x00,
                  0x00,
                  0x01,
                  (byte) 0xFF
                }));
    if (response.getSW1() != 0x61) throw new Exception("Failed");
    response =
        channel.transmit(
            new CommandAPDU(new byte[] {0x00, (byte) 0xC0, 0x00, 0x00, (byte) response.getSW2()}));
    if (response.getSW() != 0x9000) throw new Exception("Failed");
    // The Above data must be analyzed to see what it means, later,.................

    // -----------------------------------------------------------------
    // Get Data... Fixed 13Hex bytes (Need anlysis)
    // --------------------------------------------------------------------
    response =
        channel.transmit(
            new CommandAPDU(new byte[] {(byte) 0x80, (byte) 0xCA, 0x01, 0x01, 0x13})); //
    if (response.getSW() != 0x9000) throw new Exception("Failed");
    return response.getData();
  }
Exemplo n.º 3
0
  public String getCardSerialNumber() throws Exception {
    // Select first file
    // response = selectFile(channel, new byte[]{0x00, 0x02, 0x43, 0x00, 0x13, 0x00, 0x00, 0x00,
    // 0x01, 0x01});
    ResponseAPDU response =
        this.channel.transmit(
            new CommandAPDU(
                new byte[] {
                  0x00,
                  (byte) 0xA4,
                  0x04,
                  0x00,
                  0x0C,
                  (byte) 0xA0,
                  0x00,
                  0x00,
                  0x02,
                  0x43,
                  0x00,
                  0x13,
                  0x00,
                  0x00,
                  0x00,
                  0x01,
                  0x01
                }));
    if (response.getSW1() != 0x61) throw new Exception("Response error getting CardSerialNo");
    // read from first file
    response = getResponseStd(channel, response.getSW2());
    ; // Not used data for now
    mProperty0 = response.getData().clone();

    response =
        channel.transmit(
            new CommandAPDU(new byte[] {(byte) 0x80, (byte) 0xC0, 0x02, (byte) 0xA1, 0x08}));
    if (response.getSW() != 0x9000) throw new Exception("Failed to get Card serial no");
    return HexToChar(response.getData());
  }
Exemplo n.º 4
0
  private void setPublicData(EidPublicData eid) throws Exception {

    ResponseAPDU response;
    response =
        channel.transmit(
            new CommandAPDU(new byte[] {0x00, (byte) 0xA4, 0x00, 0x00, 0x02, 0x02, 0x03}));
    if (response.getSW1() != 0x61) throw new Exception("Failed");
    response =
        channel.transmit(
            new CommandAPDU(new byte[] {0x00, (byte) 0xC0, 0x00, 0x00, (byte) response.getSW2()}));
    if (response.getSW() != 0x9000) throw new Exception("Failed");
    mProperty2 = response.getData().clone();

    // Read real data
    response =
        channel.transmit(new CommandAPDU(new byte[] {0x00, (byte) 0xB0, 0x00, 0x00, (byte) 0xE6}));
    if (response.getSW() != 0x9000) throw new Exception("Failed to read public data v1");

    byte[] data = response.getData(); // Reference to data
    int nexIndex = 0;
    int endIndex = ARABIC_FULL_NAME_OFFS - 2;

    int startIndex = getNextZero(data, 0);
    int length = data[startIndex + 1];

    int typeId = 0;

    while (startIndex < data.length) {
      if (length == 0) {
        startIndex = getNextZero(data, startIndex);
        length = data[startIndex + 1];
      }

      byte[] tobeExtracted = new byte[length];

      System.arraycopy(data, startIndex + 2, tobeExtracted, 0, length);

      switch (typeId) {
        case 1:
          eid.setIssueDate(Utils.CharArrayToStringDate(Utils.ToCharArray(tobeExtracted)));
          break;
        case 2:
          eid.setExpiryDate(Utils.CharArrayToStringDate(Utils.ToCharArray(tobeExtracted)));
          break;
        case 4:
          eid.setArabicFullName(Utils.CharArrayToUTF8String(Utils.ToCharArray(tobeExtracted)));
          break;
        case 6:
          eid.setFullName(Utils.CharArrayToUTF8String(Utils.ToCharArray(tobeExtracted)));
          break;
        case 7:
          eid.setSex(Utils.CharArrayToUTF8String(Utils.ToCharArray(tobeExtracted)));
          break;
        case 10:
          eid.setNationality(Utils.CharArrayToUTF8String(Utils.ToCharArray(tobeExtracted)));
          break;
        case 11:
          eid.setDateOfBirth(Utils.CharArrayToStringDate(Utils.ToCharArray(tobeExtracted)));
          break;
      }

      if (typeId >= 13) break;

      startIndex = getNextZero(data, startIndex + 2);
      length = data[startIndex + 1];
      typeId = typeId + 1;
    }

    // Read real data
    response =
        channel.transmit(new CommandAPDU(new byte[] {0x00, (byte) 0xB0, 0x00, 0x00, (byte) 0xE6}));
    if (response.getSW() != 0x9000) throw new Exception("Failed to read public data v1");

    data = response.getData(); // Reference to data
    byte a = data[0];

    /*int index = 0;
    String transformed = new String(data, UTF8_CHARSET);*/

    // ---- ISSUE DATE -------------------------------------------------------
    /*{

        String text = HexToChar(data);

        index = getNextZero(data, index);




        endIndex = getNextZero(data, index + 1);

        int length = endIndex - nexIndex;

        byte[] date1 = new byte[length];
        System.arraycopy(data, index+2, date1, 0, length);
        eid.setIssueDate(Utils.CharArrayToStringDate(Utils.ToCharArray(date1)));

        //---- ISSUE DATE -------------------------------------------------------
        System.arraycopy(data, EXPIRY_DATE_OFFS, date1, 0, date1.length);
        eid.setExpiryDate(Utils.CharArrayToStringDate(Utils.ToCharArray(date1)));

        //---- BIRTH DATE -------------------------------------------------------
        System.arraycopy(data, BIRTH_DATE_OFFS, date1, 0, date1.length);
        eid.setDateOfBirth(Utils.CharArrayToStringDate(Utils.ToCharArray(date1)));
    }
    //---- ARABIC NAME -----------------------------------------------------------------
    /*{
        int endIndex = getNextZero(data, ARABIC_FULL_NAME_OFFS);
        int length = endIndex - ARABIC_FULL_NAME_OFFS;

        //byte[] arabic_name = new byte[data[ARABIC_FULL_NAME_OFFS - 1]];
        byte[] arabic_name = new byte[length];
        System.arraycopy(data, ARABIC_FULL_NAME_OFFS, arabic_name, 0, arabic_name.length);
        eid.setArabicFullName(Utils.CharArrayToUTF8String(Utils.ToCharArray(arabic_name)));

        nexIndex = getNextNonZero(data, endIndex + 1);
    }*/
    // ---- ENGLISH NAME
    /*{

        int endIndex = getNextZero(data, nexIndex);
        int length = endIndex - nexIndex;


        byte[] english_name = new byte[length];
        System.arraycopy(data, nexIndex, english_name, 0, english_name.length);
        eid.setFullName(Utils.CharArrayToUTF8String(Utils.ToCharArray(english_name)));
    }*/
    // --- NATIONALITY CODE-------------------------------------------------------------
    /* {
        byte[] nationalityCode = new byte[NATIONALITY_CODE_OFFS - 1];

        //int destIndex = data.length - NATIONALITY_CODE_OFFS - 1;



        System.arraycopy(data, NATIONALITY_CODE_OFFS, nationalityCode, 0, 3);
        String nationality = Utils.CharArrayToUTF8String(Utils.ToCharArray(nationalityCode));
        eid.setNationality(nationality);
    }
    //--- sex ---------------------------------------------------------------------------
    {
        byte[] sex = new byte[]{data[SEX_OFFS]};
        eid.setSex(Utils.CharArrayToUTF8String(Utils.ToCharArray(sex)));
    }
    //-- ID Type ----------------------------------------------------------
    {
        byte[] idType = new byte[ID_TYPE_OFFS-1];
        System.arraycopy(data, ENGLISH_FULL_NAME_OFFS, idType, 0, idType.length);
        eid.setIDType(Utils.CharArrayToUTF8String(Utils.ToCharArray(idType)));
    }*/

    android.util.Log.v("Done with public data", "Public data has been converted successfully");
  }