opencard.opt.util
Class PassThruCardService
java.lang.Object
|
+--opencard.core.service.CardService
|
+--opencard.opt.util.PassThruCardService
- public class PassThruCardService
- extends opencard.core.service.CardService
A card service for low level communication with smartcards.
It allows to send application-provided command APDUs to the card and
returns the response APDUs. The factory that creates this service is
PassThruCardServiceFactory.
This class serves as an example how a card service can be implemented.
However, it contradicts the idea of card services. The responsibility
for composing the APDUs sent to the card and interpreting the responses
lies with the card services, not with the application.
Since most people start getting familiar with smartcards by building
APDUs themselves, this service is provided here as a "quick starter"
for some test programs. Nevertheless, it's use is strongly discouraged
when implementing real applications.
OpenCard applications should never build APDUs, since APDUs are
card specific. The same applies to interpreting the responses received
from the smartcard. Instead, they should use high-level interfaces that
can be implemented for different cards. These interfaces can be standard
interfaces, like FileAccessCardService for ISO compatible, file
system based smartcards, or they can be defined by an application.
When designing an application that supports smartcards, there will
typically be a need for two kinds of card specific code. First, the
ATR sent by a smartcard has to be interpreted to make sure that the
card inserted is supported by the application. An OCF application
should put the respective code into a card service factory, or use an
existing factory that knows the ATR(s).
The second part of the card specific code will build command APDUs and
interpret responses to these commands. This part of the code can provide
rather general operations, like select a file or read some
data from a file. In this case, a standard interface should be used.
On the other hand, this part of the code can also provide specialized
functionality, like read the serial number or read the card
holder's name. In this case, the application should define it's own
interface, and a card service implementing this interface has to be
developed.
Later on, if another card with different APDUs and responses has to be
supported by the same application, just a service for that new card has
to be developed, implementing the same interface as the first one. The
factory used to create the first service will be extended, so it can
decide which service to use, depending on a smartcard's ATR. The
application itself does not have to be changed at all.
- See Also:
PassThruCardServiceFactory
,
FileAccessCardService
Constructor Summary |
PassThruCardService()
Creates a new low level card service that is not yet initialized.
|
Method Summary |
opencard.core.terminal.ResponseAPDU |
sendCommandAPDU(opencard.core.terminal.CommandAPDU command)
Sends a CommandAPDU to the smart card. |
Methods inherited from class opencard.core.service.CardService |
allocateCardChannel,
getCard,
getCardChannel,
getCHVDialog,
initialize,
releaseCardChannel,
setCardChannel,
setCHVDialog |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
PassThruCardService
public PassThruCardService()
- Creates a new low level card service that is not yet initialized.
Initialization is done by invoking initialize in the base class.
- See Also:
CardService.initialize(opencard.core.service.CardServiceScheduler, opencard.core.service.SmartCard, boolean)
sendCommandAPDU
public opencard.core.terminal.ResponseAPDU sendCommandAPDU(opencard.core.terminal.CommandAPDU command)
throws opencard.core.terminal.CardTerminalException
- Sends a CommandAPDU to the smart card.
- Parameters:
command
- The CommandAPDU to send.- Returns:
- The resulting ResponseAPDU as
received from the card.
- Throws:
- opencard.core.terminal.CardTerminalException - if the terminal encountered an error while
trying to communicate with the smartcard