org.eclipse.keyple.card.calypso.CommandGetDataFcp Maven / Gradle / Ivy
Show all versions of keyple-card-calypso-java-lib Show documentation
/* **************************************************************************************
* Copyright (c) 2018 Calypso Networks Association https://calypsonet.org/
*
* See the NOTICE file(s) distributed with this work for additional information
* regarding copyright ownership.
*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
************************************************************************************** */
package org.eclipse.keyple.card.calypso;
import static org.eclipse.keyple.card.calypso.DtoAdapters.*;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.keyple.core.util.ApduUtil;
import org.eclipse.keypop.card.ApduResponseApi;
/**
* Builds the Get data APDU commands for the FCP tag.
*
* In contact mode, this command can not be sent in a secure session because it would generate a
* 6Cxx status and thus make calculation of the digest impossible.
*
*
The value of the Proprietary Information tag is extracted from the Select File response and
* made available using the corresponding getter.
*
* @since 2.0.1
*/
final class CommandGetDataFcp extends Command {
private static final Map STATUS_TABLE;
static {
Map m = new HashMap<>(Command.STATUS_TABLE);
m.put(
0x6A88,
new StatusProperties(
"Data object not found (optional mode not available)", CardDataAccessException.class));
m.put(0x6A82, new StatusProperties("File not found", CardDataAccessException.class));
m.put(
0x6B00,
new StatusProperties("P1 or P2 value not supported", CardDataAccessException.class));
STATUS_TABLE = m;
}
/**
* Constructor.
*
* @param transactionContext The global transaction context common to all commands.
* @param commandContext The local command context specific to each command.
* @since 2.3.2
*/
CommandGetDataFcp(TransactionContextDto transactionContext, CommandContextDto commandContext) {
super(CardCommandRef.GET_DATA, 0, transactionContext, commandContext);
byte cardClass =
transactionContext.getCard() != null
? transactionContext.getCard().getCardClass().getValue()
: CalypsoCardClass.ISO.getValue();
setApduRequest(
new ApduRequestAdapter(
ApduUtil.build(
cardClass,
getCommandRef().getInstructionByte(),
CalypsoCardConstant.TAG_FCP_FOR_CURRENT_FILE_MSB,
CalypsoCardConstant.TAG_FCP_FOR_CURRENT_FILE_LSB,
null,
(byte) 0x00)));
addSubName("FCP_FOR_CURRENT_FILE");
}
/**
* {@inheritDoc}
*
* @since 2.3.2
*/
@Override
void finalizeRequest() {
encryptRequestAndUpdateTerminalSessionMacIfNeeded();
}
/**
* {@inheritDoc}
*
* @since 2.3.2
*/
@Override
boolean isCryptoServiceRequiredToFinalizeRequest() {
return getCommandContext().isEncryptionActive();
}
/**
* {@inheritDoc}
*
* @since 2.3.2
*/
@Override
boolean synchronizeCryptoServiceBeforeCardProcessing() {
return !getCommandContext().isSecureSessionOpen();
}
/**
* {@inheritDoc}
*
* @since 2.3.2
*/
@Override
void parseResponse(ApduResponseApi apduResponse) throws CardCommandException {
decryptResponseAndUpdateTerminalSessionMacIfNeeded(apduResponse);
super.setApduResponseAndCheckStatus(apduResponse);
CommandSelectFile.parseProprietaryInformation(
apduResponse.getDataOut(), getTransactionContext().getCard());
updateTerminalSessionIfNeeded();
}
/**
* {@inheritDoc}
*
* @since 2.0.1
*/
@Override
Map getStatusTable() {
return STATUS_TABLE;
}
}