Package org.nfctools.mf

Examples of org.nfctools.mf.MfLoginException


  }

  @SuppressWarnings("null")
  private static TrailerBlock readTrailerBlock(MfClassicReaderWriter readerWriter, int sector, KeyValue... keys)
      throws IOException {
    MfLoginException lastException = null;
    for (KeyValue keyValue : keys) {
      try {
        MemoryLayout memoryLayout = readerWriter.getMemoryLayout();
        int trailerBlockNumberForSector = memoryLayout.getTrailerBlockNumberForSector(sector);
        MfClassicAccess access = new MfClassicAccess(keyValue, sector, trailerBlockNumberForSector);
View Full Code Here


    try {
      CommandAPDU loadKey = new CommandAPDU(Apdu.CLS_PTS, Apdu.INS_EXTERNAL_AUTHENTICATE,
          Acs.P1_LOAD_KEY_INTO_VOLATILE_MEM, memoryKeyId, mfAccess.getKeyValue());
      ResponseAPDU loadKeyResponse = cardChannel.transmit(loadKey);
      if (!ApduUtils.isSuccess(loadKeyResponse)) {
        throw new MfLoginException("Loading key failed. Sector: " + mfAccess.getSector() + ", Block: "
            + mfAccess.getBlock() + " Key: " + mfAccess.getKey().name() + ", Response: " + loadKeyResponse);
      }

      byte blockNumber = (byte)mfAccess.getCard().getBlockNumber(mfAccess.getSector(), mfAccess.getBlock());

      byte keyTypeToUse = mfAccess.getKey() == Key.A ? Acs.KEY_A : Acs.KEY_B;

      CommandAPDU auth = new CommandAPDU(Apdu.CLS_PTS, Apdu.INS_INTERNAL_AUTHENTICATE_ACS, 0, 0, new byte[] {
          0x01, 0x00, blockNumber, keyTypeToUse, memoryKeyId });
      ResponseAPDU authResponse = cardChannel.transmit(auth);
      if (!ApduUtils.isSuccess(authResponse)) {
        throw new MfLoginException("Login failed. Sector: " + mfAccess.getSector() + ", Block: "
            + mfAccess.getBlock() + " Key: " + mfAccess.getKey().name() + ", Response: " + authResponse);
      }
    }
    catch (CardException e) {
      throw new IOException(e);
View Full Code Here

    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: "
          + NfcUtils.convertBinToASCII(key));

    }
View Full Code Here

        trailerBlockId));

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

    if (Key.B.equals(mfAccess.getKey()) && trailerBlock.isKeyBReadable())
      throw new MfLoginException("Cannot login with Key B. Key B is readable. Sector: " + mfAccess.getSector()
          + ", Block: " + blockId);

    int dataArea = (int)(mfAccess.getCard().getBlocksPerSector(mfAccess.getSector()) > 3 ? Math
        .floor((double)mfAccess.getCard().getBlocksPerSector(mfAccess.getSector()) / 5.0) : blockId);

    if ((blockId == trailerBlockId && !trailerBlock.canWriteTrailerBlock(mfAccess.getKey()))
        || (blockId != trailerBlockId && !trailerBlock.canWriteDataBlock(mfAccess.getKey(), dataArea))) {
      throw new MfLoginException("Write Access Denied. Sector: " + mfAccess.getSector() + ", Block: " + blockId
          + " Key: " + mfAccess.getKey().name());

    }

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

  }

  private void throwException(MfAccess mfAccess, ArygonMessage message, String exceptionMessage) throws IOException {
    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

        + NfcUtils.convertBinToASCII(mfAccess.getKeyValue());
    nfcReaderWriter.sendMessage(loginMessage.getBytes());
    ArygonMessage message = nfcReaderWriter.receiveMessage();
    if (message.hasTamaErrorCode()) {
      reselectCard(mfAccess.getCard());
      throw new MfLoginException("Login failed. Sector: " + mfAccess.getSector() + ", Block: "
          + mfAccess.getBlock() + " Key: " + mfAccess.getKey().name() + ", Tama: "
          + new String(message.getPayload()));
    }
  }
View Full Code Here

    int memoryKeyId = loginKeyHandler.getNextKeyPosition();
    Command loadKey = new Command(Apdu.INS_EXTERNAL_AUTHENTICATE, Acs.P1_LOAD_KEY_INTO_VOLATILE_MEM, memoryKeyId,
        access.getKeyValue().getKeyValue());
    Response loadKeyResponse = apduTag.transmit(loadKey);
    if (!loadKeyResponse.isSuccess()) {
      throw new MfLoginException("Loading key failed. Sector: " + access.getSector() + ", Block: "
          + access.getBlock() + " Key: " + access.getKeyValue().getKey().name() + ", Response: "
          + loadKeyResponse);
    }
    loginKeyHandler.rememberKey(access);
    return memoryKeyId;
View Full Code Here

    Command auth = new Command(Apdu.INS_INTERNAL_AUTHENTICATE_ACS, 0, 0, new byte[] { 0x01, 0x00, blockNumber,
        keyTypeToUse, (byte)memoryKeyId });
    Response authResponse = apduTag.transmit(auth);
    if (!authResponse.isSuccess()) {
      loginKeyHandler.resetCurrentKeys();
      throw new MfLoginException("Login failed. Sector: " + access.getSector() + ", Block: " + access.getBlock()
          + " Key: " + access.getKeyValue().getKey().name() + ", Response: " + authResponse);
    }
    else {
      loginKeyHandler.setSuccessfulLogin(access);
    }
View Full Code Here

TOP

Related Classes of org.nfctools.mf.MfLoginException

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.