Interface ApduInterpreterSpi
Its implementation is provided by ApduInterpreterFactorySpi.
Upon calling processApdu, implementations determine how to invoke the appropriate
methods of CommandProcessorApi based on the APDU class byte (CLA) and instruction (INS).
APDU Processing Strategy
The interpreter follows a two-pathway processing model:
- Standard ISO 7816-4 APDUs (CLA != 0xFF): Directly transmitted via
CommandProcessorApi.transmitIsoApdu(byte[])without interpretation. - Storage Card APDUs (CLA = 0xFF): Interpreted and translated into
CommandProcessorApi method calls based on the instruction byte:
INS 0xCA→CommandProcessorApi.getUID()- Get card UIDINS 0xB0→CommandProcessorApi.readBlock(int, int)- Read binary dataINS 0xD6→CommandProcessorApi.writeBlock(int, byte[])- Write binary dataINS 0x82→CommandProcessorApi.loadKey(KeyStorageType, int, byte[])- Load authentication keyINS 0x86→CommandProcessorApi.generalAuthenticate(int, int, int)- Authenticate with key
Error Handling Strategy
This interface follows a trust-based validation approach:
- Validation is performed upstream by the card extension that generates the APDUs. Since this extension is part of the same ecosystem, its output is trusted.
CommandProcessorApidoes not perform parameter validation and trusts the incoming data to be correct.- Exceptions propagate to the caller unless they represent normal protocol conditions (e.g., authentication failure, unsupported instruction).
- Status words are returned only for protocol-level conditions, not validation errors.
Status Words Usage
Implementations return ISO 7816-4 / PC/SC compliant status words for the following conditions:
| Status Word | Code | Usage |
|---|---|---|
| Success | 0x9000 | Successful execution |
| Security status not satisfied | 0x6982 | Authentication failed (PC/SC compliant) |
| INS not supported | 0x6D00 | Unknown instruction code |
Exception Propagation
The following error conditions may result in exceptions:
- Hardware/communication errors (card not responding, transmission failure)
- thrown by
CommandProcessorApi - Protocol-level errors that cannot be represented by status words - may be thrown by implementations
Note: Parameter validation (P1/P2 values, data lengths, key numbers, etc.) is the responsibility of the card extension generating the APDUs, not this interface or its implementations.
PC/SC Compliance
Storage card commands (CLA=0xFF) follow the PC/SC v2.01.09 specification:
- LOAD KEY:
FF 82 [P1] [P2] 06 [6-byte key] - GENERAL AUTHENTICATE:
FF 86 00 00 05 [version][addr-MSB][addr-LSB][key-type][key-num] - GET DATA (UID):
FF CA 00 00 [Le] - READ BINARY:
FF B0 [P1] [P2] [Le] - UPDATE BINARY:
FF D6 [P1] [P2] [Lc] [data]
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]processApdu(byte[] apdu) Processes an APDU command by invoking the corresponding methods ofCommandProcessorApibased on the card type.voidsetCommandProcessor(CommandProcessorApi commandProcessor) Sets the command processor responsible for handling APDU execution.
-
Method Details
-
setCommandProcessor
Sets the command processor responsible for handling APDU execution.- Parameters:
commandProcessor- TheCommandProcessorApiinstance used for APDU communication.- Since:
- 1.0.0
-
processApdu
Processes an APDU command by invoking the corresponding methods ofCommandProcessorApibased on the card type.If the card supports standard ISO 7816-4 APDUs, this method calls
CommandProcessorApi.transmitIsoApdu(byte[]). Otherwise, it interprets the APDU and executes the required read or write operations throughCommandProcessorApi.readBlock(int, int)orCommandProcessorApi.writeBlock(int, byte[]).- Parameters:
apdu- The APDU command as a byte array.- Returns:
- The response as a byte array.
- Throws:
IllegalArgumentException- if the APDU is null or invalid.Exception- if the transmission fails or a communication error occurs.- Since:
- 1.0.0
-