Package org.nfctools.mf

Examples of org.nfctools.mf.MfException


        if (writeKeyValue == null)
          mad.setReadonly();
        return mad;
      }
      else {
        throw new MfException("MAD version not supported");
      }
    }
    else {
      throw new MfException("MAD not available");
    }
  }
View Full Code Here


      CommandAPDU readBlock = new CommandAPDU(Apdu.CLS_PTS, Apdu.INS_READ_BINARY, 0x00, blockNumber, 16);
      ResponseAPDU readBlockResponse;
      try {
        readBlockResponse = cardChannel.transmit(readBlock);
        if (!ApduUtils.isSuccess(readBlockResponse)) {
          throw new MfException("Reading block failed. Sector: " + mfAccess.getSector() + ", Block: "
              + mfAccess.getBlock() + " Key: " + mfAccess.getKey().name() + ", Response: "
              + readBlockResponse);
        }

      }
View Full Code Here

      int blockNumber = mfAccess.getCard().getBlockNumber(mfAccess.getSector(), mfAccess.getBlock())
          + currentBlock;

      if (mfAccess.getCard().isTrailerBlock(mfAccess.getSector(), mfAccess.getBlock() + currentBlock)) {
        if (!(mfBlock[currentBlock] instanceof TrailerBlock))
          throw new MfException("invalid block for trailer");
      }

      CommandAPDU writeBlock = new CommandAPDU(Apdu.CLS_PTS, Apdu.INS_UPDATE_BINARY, 0x00, blockNumber,
          mfBlock[currentBlock].getData());
      ResponseAPDU writeBlockResponse;
      try {
        writeBlockResponse = cardChannel.transmit(writeBlock);
        if (!ApduUtils.isSuccess(writeBlockResponse)) {
          throw new MfException("Writing block failed. Sector: " + mfAccess.getSector() + ", Block: "
              + mfAccess.getBlock() + " Key: " + mfAccess.getKey().name() + ", Response: "
              + writeBlockResponse);
        }

      }
View Full Code Here

        case 2:
          return new MfCard4k(new byte[0], connectionToken);
      }
    }

    throw new MfException("unknown card type: " + NfcUtils.convertBinToASCII(historicalBytes));

  }
View Full Code Here

    Collection<String> lines = readLinesFromFile(fileName);

    MfCard mfCard = lines.size() == 256 ? new MfCard4k(null, null) : lines.size() == 64 ? new MfCard1k(null, null)
        : null;
    if (mfCard == null)
      throw new MfException("unknown card. lines " + lines.size());

    BlockResolver blockResolver = new BlockResolver();

    Map<Integer, MfBlock> blockMap = new HashMap<Integer, MfBlock>();
    int blockNumber = 0;
View Full Code Here

        trailerBlockId));

    byte[] key = trailerBlock.getKey(mfAccess.getKey());

    if (Key.B.equals(mfAccess.getKey()) && trailerBlock.isKeyBReadable())
      throw new MfException("Cannot login with Key B. Key B is readable");

    if (!NfcUtils.isEqualArray(key, mfAccess.getKeyValue())) {
      throw new MfLoginException("Login failed. Sector: " + mfAccess.getSector() + ", Block: "
          + mfAccess.getBlock() + " Key: " + mfAccess.getKey().name() + " Given: "
          + NfcUtils.convertBinToASCII(mfAccess.getKeyValue()) + ", Expected: "
View Full Code Here

  }

  public TrailerBlock(byte data[]) throws MfException {
    super(data, BLOCK_TYPE_TRAIL);
    if (!validAccessConditions(getAccessConditions())) {
      throw new MfException("illegal trailer block");
    }
  }
View Full Code Here

  public void setAccessConditions(byte[] acValue) throws MfException {
    if (validAccessConditions(acValue))
      System.arraycopy(acValue, 0, data, ACCESS_CONDITIONS_INDEX, acValue.length);
    else
      throw new MfException("illegal access conditions");
  }
View Full Code Here

   * @throws MfException
   */
  public void decypherValueBlock(byte[] valueBlock) throws MfException {
    for (int x = 0; x < 4; x++) {
      if ((valueBlock[x] != ~valueBlock[x + 4]) || (valueBlock[x] != valueBlock[x + 8]))
        throw new MfException("Not a valid value block. [" + NfcUtils.convertBinToASCII(valueBlock) + "]");
    }
    if ((valueBlock[12] != ~valueBlock[13]) || (valueBlock[12] != valueBlock[14])
        || (valueBlock[13] != valueBlock[15]))
      throw new MfException("Not a valid value block. [" + NfcUtils.convertBinToASCII(valueBlock) + "]");

    value = NfcUtils.bytesToInt(valueBlock, 0);
    address = valueBlock[12];
  }
View Full Code Here

    if (message.getTamaErrorCode() == 0x13) {
      reselectCard(mfAccess.getCard());
      throw new MfLoginException("Cannot login.");
    }
    else
      throw new MfException(exceptionMessage + " Sector: " + mfAccess.getSector() + ", Block: "
          + mfAccess.getBlock() + " Key: " + mfAccess.getKey().name() + ", Tama: "
          + new String(message.getPayload()) + " TamaCode: " + message.getTamaErrorCode());
  }
View Full Code Here

TOP

Related Classes of org.nfctools.mf.MfException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.