org.eclipse.keyple.card.calypso.CommandInvalidate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of keyple-card-calypso-java-lib Show documentation
Show all versions of keyple-card-calypso-java-lib Show documentation
Keyple add-on to manage Calypso cards
/* **************************************************************************************
* Copyright (c) 2020 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 Invalidate command.
*
* @since 2.0.1
*/
final class CommandInvalidate extends Command {
private static final Map STATUS_TABLE;
static {
Map m = new HashMap<>(Command.STATUS_TABLE);
m.put(
0x6400,
new StatusProperties(
"Too many modifications in session", CardSessionBufferOverflowException.class));
m.put(0x6700, new StatusProperties("Lc value not supported", CardDataAccessException.class));
m.put(
0x6982,
new StatusProperties(
"Security conditions not fulfilled (no session, wrong key)",
CardSecurityContextException.class));
m.put(
0x6985,
new StatusProperties(
"Access forbidden (DF context is invalid)", CardAccessForbiddenException.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
*/
CommandInvalidate(TransactionContextDto transactionContext, CommandContextDto commandContext) {
super(CardCommandRef.INVALIDATE, 0, transactionContext, commandContext);
setApduRequest(
new ApduRequestAdapter(
ApduUtil.build(
getTransactionContext().getCard().getCardClass().getValue(),
getCommandRef().getInstructionByte(),
(byte) 0x00,
(byte) 0x00,
null,
null)));
}
/**
* {@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() {
if (getCommandContext().isEncryptionActive()) {
return false;
}
updateTerminalSessionIfNeeded(APDU_RESPONSE_9000);
return true;
}
/**
* {@inheritDoc}
*
* @since 2.3.2
*/
@Override
void parseResponse(ApduResponseApi apduResponse) throws CardCommandException {
decryptResponseAndUpdateTerminalSessionMacIfNeeded(apduResponse);
super.setApduResponseAndCheckStatus(apduResponse);
updateTerminalSessionIfNeeded();
// The DF has been successfully invalidated, update the DF status in the card object
getTransactionContext().getCard().setDfInvalidated(true);
}
/**
* {@inheritDoc}
*
* @since 2.0.1
*/
@Override
Map getStatusTable() {
return STATUS_TABLE;
}
}