コード例 #1
0
  /* (non-Javadoc)
   * @see org.opensc.pkcs15.token.Token#deleteEF(int)
   */
  @Override
  public void deleteEF(int path) throws IOException {

    // DELETE FILE, P1=0x00, P2=0x00, ID -> read current EF from position 0.
    CommandAPDU cmd =
        new CommandAPDU(0x00, 0xE4, 0x00, 0x00, PathHelper.idToPath(path), DEFAULT_LE);

    try {
      ResponseAPDU resp = this.channel.transmit(cmd);

      if (resp.getSW() != PKCS15Exception.ERROR_OK)
        throw new PKCS15Exception(
            "DELETE FILE for EF ["
                + PathHelper.formatPathAppend(this.currentFile.getPath(), path)
                + "] returned error",
            resp.getSW());

    } catch (CardException e) {
      throw new PKCS15Exception(
          "Error sending DELETE FILE for EF ["
              + PathHelper.formatPathAppend(this.currentFile.getPath(), path)
              + "]",
          e);
    }
  }
コード例 #2
0
  /* (non-Javadoc)
   * @see org.opensc.pkcs15.token.Token#createEF(int, org.opensc.pkcs15.token.EFAcl)
   */
  @Override
  public EF createEF(int path, long size, EFAcl acl) throws IOException {

    if (size < 0 || size > 65535L)
      throw new PKCS15Exception(
          "Illegal size ["
              + size
              + "] for EF ["
              + PathHelper.formatPathAppend(this.currentFile.getPath(), path)
              + "].",
          PKCS15Exception.ERROR_INVALID_PARAMETER);

    ByteArrayOutputStream bos = new ByteArrayOutputStream(256);
    DataOutputStream dos = new DataOutputStream(bos);

    dos.write(0x62);
    // length of subsequent FCP data field, to be filled at end.
    dos.write(0x00);

    // *** fill in FCP data
    //   Only EF:      Net size in bytes
    dos.write(0x80);
    dos.write(0x02);
    dos.writeShort((int) size);

    // File descriptor: 01h BINARY
    dos.write(0x82);
    dos.write(0x01);
    dos.write(0x01);

    // File ID
    dos.write(0x83);
    dos.write(0x02);
    dos.writeShort(path);

    // Default file status.
    dos.write(0x85);
    dos.write(0x01);
    dos.write(0x00);

    // ACL definitions
    dos.write(0x86);
    dos.write(0x09);
    dos.write(acl.getAcRead());
    dos.write(acl.getAcUpdate());
    dos.write(acl.getAcAppend());
    dos.write(acl.getAcDeactivate());
    dos.write(acl.getAcActivate());
    dos.write(acl.getAcDelete());
    dos.write(acl.getAcAdmin());
    dos.write(acl.getAcIncrease());
    dos.write(acl.getAcDecrease());

    // *** get command data.
    dos.flush();
    byte[] data = bos.toByteArray();

    // fill in length of subsequent FCP data field, to be filled at end.
    data[1] = (byte) (data.length - 2);

    // CREATE FILE, P1=0x00, P2=0x00, ID -> read current EF from position 0.
    CommandAPDU cmd = new CommandAPDU(0x00, 0xE0, 0x00, 0x00, data, DEFAULT_LE);

    try {
      ResponseAPDU resp = this.channel.transmit(cmd);

      if (resp.getSW() != PKCS15Exception.ERROR_OK)
        throw new PKCS15Exception(
            "CREATE FILE for EF ["
                + PathHelper.formatPathAppend(this.currentFile.getPath(), path)
                + "] returned error",
            resp.getSW());

    } catch (CardException e) {
      throw new PKCS15Exception(
          "Error sending CREATE FILE for EF ["
              + PathHelper.formatPathAppend(this.currentFile.getPath(), path)
              + "]",
          e);
    }

    return new EF(new TokenPath(this.currentFile.getPath(), path), size, acl);
  }