public class PoTransaction
extends java.lang.Object
Depending on the type of operations required, the presence of a SAM may be necessary.
The CalypsoPo object provided to the build is kept and updated at each step of using
the service. It is the main container of the data handled during the transaction and acts as a
card image.
There are two main steps in using the methods of this service:
CalypsoPo.
CalypsoPo.
Technical or data errors, security conditions, etc. are reported as exceptions.
| Modifier and Type | Class and Description |
|---|---|
static class |
PoTransaction.PinTransmissionMode
Defines the PIN transmission modes: plain or encrypted.
|
static class |
PoTransaction.SessionSetting
Contains the Calypso Secure Session set of parameters.
|
static class |
PoTransaction.SvSettings
Defines the Stored Value transactions parameters
|
| Constructor and Description |
|---|
PoTransaction(org.eclipse.keyple.core.card.selection.CardResource<CalypsoPo> poResource)
Constructor.
|
PoTransaction(org.eclipse.keyple.core.card.selection.CardResource<CalypsoPo> poResource,
PoSecuritySettings poSecuritySettings)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
prepareAppendRecord(byte sfi,
byte[] recordData)
Schedules the execution of a Append Record command to adds the data provided in the
indicated cyclic file.
|
void |
prepareCheckPinStatus()
Schedules the execution of a Verify Pin command without PIN presentation in order to get
the attempt counter.
|
void |
prepareDecreaseCounter(byte sfi,
int counterNumber,
int decValue)
Schedules the execution of a Decrease command command to decrease the target counter.
|
void |
prepareIncreaseCounter(byte sfi,
int counterNumber,
int incValue)
Schedules the execution of a Increase command command to increase the target counter.
|
void |
prepareInvalidate()
Schedules the execution of a Invalidate command.
|
void |
prepareReadCounterFile(byte sfi,
int countersNumber)
Schedules the execution of a Read Records command to reads a record of the indicated EF,
which should be a counter file.
|
void |
prepareReadRecordFile(byte sfi,
int recordNumber)
Schedules the execution of a Read Records command to read a single record from the
indicated EF.
|
void |
prepareReadRecordFile(byte sfi,
int firstRecordNumber,
int numberOfRecords,
int recordSize)
Schedules the execution of a Read Records command to read one or more records from the
indicated EF.
|
void |
prepareRehabilitate()
Schedules the execution of a Rehabilitate command.
|
void |
prepareReleasePoChannel()
Requests the closing of the PO channel.
|
void |
prepareSelectFile(byte[] lid)
Schedules the execution of a Select File command based on the file's LID.
|
void |
prepareSelectFile(SelectFileControl control)
Schedules the execution of a Select File command using a navigation control defined by
the ISO standard.
|
void |
prepareSetCounter(byte sfi,
int counterNumber,
int newValue)
Schedules the execution of a command to set the value of the target counter.
|
void |
prepareSvDebit(int amount)
Schedules the execution of a SV Debit or SV Undebit command to increase the
current SV balance or to partially or totally cancels the last SV debit command.
|
void |
prepareSvDebit(int amount,
byte[] date,
byte[] time)
Schedules the execution of a SV Debit or SV Undebit command to increase the
current SV balance or to partially or totally cancels the last SV debit command and using the
provided additional data.
|
void |
prepareSvGet(PoTransaction.SvSettings.Operation svOperation,
PoTransaction.SvSettings.Action svAction)
Schedules the execution of a SV Get command to prepare an SV operation or simply
retrieves the current SV status.
|
void |
prepareSvReadAllLogs()
Schedules the execution of Read Records commands to read all SV logs.
|
void |
prepareSvReload(int amount)
Schedules the execution of a SV Reload command to increase the current SV balance.
|
void |
prepareSvReload(int amount,
byte[] date,
byte[] time,
byte[] free)
Schedules the execution of a SV Reload command to increase the current SV balance and
using the provided additional data.
|
void |
prepareUpdateRecord(byte sfi,
int recordNumber,
byte[] recordData)
Schedules the execution of a Update Record command to overwrites the target file's
record contents with the provided data.
|
void |
prepareWriteRecord(byte sfi,
int recordNumber,
byte[] recordData)
Schedules the execution of a Write Record command to updates the target file's record
contents with the result of a binary OR between the existing data and the provided data.
|
void |
processCancel()
Aborts a Secure Session.
|
void |
processClosing()
Terminates the Secure Session sequence started with
processOpening(SessionSetting.AccessLevel). |
void |
processOpening(PoTransaction.SessionSetting.AccessLevel accessLevel)
Opens a Calypso Secure Session and then executes all previously prepared commands.
|
void |
processPoCommands()
Process all previously prepared PO commands outside or inside a Secure Session.
|
void |
processVerifyPin(byte[] pin)
Performs a PIN verification, in order to authenticate the card holder and/or unlock access to
certain PO files.
|
void |
processVerifyPin(java.lang.String pin)
Invokes
processVerifyPin(byte[]) with a string converted into an array of bytes as
argument. |
public PoTransaction(org.eclipse.keyple.core.card.selection.CardResource<CalypsoPo> poResource, PoSecuritySettings poSecuritySettings)
Secure operations are enabled by the presence of PoSecuritySettings.
poResource - the PO resource (combination of Reader and CalypsoPo)poSecuritySettings - a set of security settings (PoSecuritySettings) including a
CardResource based on a CalypsoSam.public final void processOpening(PoTransaction.SessionSetting.AccessLevel accessLevel)
It is the starting point of the sequence:
processOpening(SessionSetting.AccessLevel)
processPoCommands()]
processPoCommands()]
processClosing()
Each of the steps in this sequence may or may not be preceded by the preparation of one or
more commands and ends with an update of the CalypsoPo object provided when
PoTransaction was created.
As a prerequisite for calling this method, since the Calypso Secure Session involves the use
of a SAM, the PoTransaction must have been built in secure mode, i.e. the constructor used must
be the one expecting a reference to a valid PoSecuritySettings object, otherwise a
CalypsoPoTransactionIllegalStateException is raised.
The secure session is opened with the PoTransaction.SessionSetting.AccessLevel passed as an
argument depending on whether it is a personalization, reload or debit transaction profile..
The possible overflow of the internal session buffer of the PO is managed in two ways
depending on the setting chosen in PoSecuritySettings.
PoTransaction.SessionSetting.ModificationMode.ATOMIC mode
and the previously prepared commands will cause the buffer to be exceeded, then an CalypsoAtomicTransactionException is raised and no transmission to the PO is made. PoTransaction.SessionSetting.ModificationMode.MULTIPLE mode
and the buffer is to be exceeded then a split into several secure sessions is performed
automatically. However, regardless of the number of intermediate sessions performed, a
secure session is opened at the end of the execution of this method.
Be aware that in the "MULTIPLE" case we lose the benefit of the atomicity of the secure session.
PO and SAM exchanges in detail
When executing this method, communications with the PO and the SAM are (in that order) :
CardRequest) of
CalypsoPo with the collected data.
Other operations carried out
processClosing()).
PoSecuritySettings and the KVC
of the card does not belong to this list then a CalypsoUnauthorizedKvcException
is thrown.
All unexpected results (communication errors, data or security errors, etc. are notified to the calling application through dedicated exceptions.
Note: to understand in detail how the secure session works please refer to the PO specification documents.
accessLevel - An PoTransaction.SessionSetting.AccessLevel enum entry.CalypsoPoTransactionIllegalStateException - if no PoSecuritySettings is availableCalypsoAtomicTransactionException - if the PO session buffer were to overflowCalypsoUnauthorizedKvcException - if the card KVC is not authorizedCalypsoPoTransactionException - if a functional error occurs (including PO and SAM IO
errors)CalypsoPoCommandException - if a response from the PO was unexpectedCalypsoSamCommandException - if a response from the SAM was unexpectedpublic final void processPoCommands()
CardRequest and sent
to the PO.
CalypsoPo object is updated with the result of the executed commands.
processClosing().processOpening(SessionSetting.AccessLevel). For example, when the PoTransaction.SessionSetting.ModificationMode.MULTIPLE mode is chosen, the commands are separated in
as many sessions as necessary to respect the capacity of the PO buffer.
CalypsoPoTransactionException - if a functional error occurs (including PO and SAM IO
errors)CalypsoPoCommandException - if a response from the PO was unexpectedCalypsoSamCommandException - if a response from the SAM was unexpectedpublic final void processClosing()
processOpening(SessionSetting.AccessLevel).
Nominal case
The previously prepared commands are integrated into the calculation of the session digest by the SAM before execution by the PO by anticipating their responses.
Thus, the session closing command containing the terminal signature is integrated into the
same APDU group sent to the PO via a final CardRequest.
Upon reception of the CardRequest PO, the signature of the PO is verified with the
SAM.
If the method terminates normally, it means that the secure session closing and all related security checks have been successful; conversely, if one of these operations fails, an exception is raised.
Stored Value
If the SV counter was debited or reloaded during the session, an additional verification specific to the SV is performed by the SAM.
Ratification
A ratification command is added after the close secure session command when the communication is done in a contactless mode.
The logical channel is closed or left open depending on whether the prepareReleasePoChannel() method has been called before or not.
PO and SAM exchanges in detail
CardRequest SAM.
CardRequest.
CardRequest PO is tolerant to
the non-reception of the answer to the ratification order.
CalypsoPoTransactionException - if a functional error occurs (including PO and SAM IO
errors)CalypsoPoCommandException - if a response from the PO was unexpectedCalypsoSamCommandException - if a response from the SAM was unexpectedpublic final void processCancel()
Send the appropriate command to the PO
Clean up internal data and status.
CalypsoPoTransactionException - if a functional error occurs (including PO and SAM IO
errors)CalypsoPoCommandException - if a response from the PO was unexpectedpublic final void processVerifyPin(byte[] pin)
This command can be performed both in and out of a secure session. The PIN code can be transmitted in plain text or encrypted according to the parameter set in PoSecuritySettings (by default the transmission is encrypted).
If the execution is done out of session but an encrypted transmission is requested, then
PoTransaction must be constructed with PoSecuritySettings
If PoTransaction is constructed without PoSecuritySettings the transmission in done
in plain.
The PO channel is closed if prepareReleasePoChannel is called before this command.
pin - the PIN code value (4-byte long byte array)CalypsoPoTransactionException - if a functional error occurs (including PO and SAM IO
errors)CalypsoPoCommandException - if a response from the PO was unexpectedCalypsoPoPinException - if the PIN presentation failed (the remaining attempt counter is
update in Calypso). See CalypsoPo.isPinBlocked() and CalypsoPo.getPinAttemptRemaining() methodsCalypsoPoTransactionIllegalStateException - if the PIN feature is not available for this
PO or if commands have been prepared before calling this process method.public final void processVerifyPin(java.lang.String pin)
processVerifyPin(byte[]) with a string converted into an array of bytes as
argument.
The provided String is converted into an array of bytes and processed with processVerifyPin(byte[]).
E.g. "1234" will be transmitted as { 0x31,0x32,0x33,0x34 }
pin - an ASCII string (4-character long)processVerifyPin(byte[])public final void prepareReleasePoChannel()
If this command is called before a "process" command (except for processOpening) then the last transmission to the PO will be associated with the indication CLOSE_AFTER in order to close the PO channel.
Note: this command must imperatively be called at the end of any transaction, whether it ended normally or not.
In case the transaction was interrupted (exception), an additional call to processPoCommands must be made to effectively close the channel.
public final void prepareSelectFile(byte[] lid)
Once this command is processed, the result is available in CalypsoPo through the
CalypsoPo.getFileBySfi(byte) and ElementaryFile.getHeader() methods.
lid - the LID of the EF to selectpublic final void prepareSelectFile(SelectFileControl control)
Once this command is processed, the result is available in CalypsoPo through the
CalypsoPo.getFileBySfi(byte) and ElementaryFile.getHeader() methods.
control - A SelectFileControl enum entrypublic final void prepareReadRecordFile(byte sfi,
int recordNumber)
Once this command is processed, the result is available in CalypsoPo.
See the method CalypsoPo.getFileBySfi(byte), the objects ElementaryFile,
FileData and their specialized methods according to the type of expected data: e.g.
FileData.getContent(int).
sfi - the SFI of the EF to readrecordNumber - the record number to readjava.lang.IllegalArgumentException - if one of the provided argument is out of rangepublic final void prepareReadRecordFile(byte sfi,
int firstRecordNumber,
int numberOfRecords,
int recordSize)
Once this command is processed, the result is available in CalypsoPo.
See the method CalypsoPo.getFileBySfi(byte), the objects ElementaryFile,
FileData and their specialized methods according to the type of expected data: e.g.
FileData.getContent().
sfi - the SFI of the EFfirstRecordNumber - the record number to read (or first record to read in case of several
records)numberOfRecords - the number of records expectedrecordSize - the record lengthjava.lang.IllegalArgumentException - if one of the provided argument is out of rangepublic final void prepareReadCounterFile(byte sfi,
int countersNumber)
The record will be read up to the counter location indicated in parameter.
Thus all previous counters will also be read.
Once this command is processed, the result is available in CalypsoPo.
See the method CalypsoPo.getFileBySfi(byte), the objects ElementaryFile,
FileData and their specialized methods according to the type of expected data: e.g.
FileData.getAllCountersValue() (int)}.
sfi - the SFI of the EFcountersNumber - the number of the last counter to be readjava.lang.IllegalArgumentException - if one of the provided argument is out of rangepublic final void prepareAppendRecord(byte sfi,
byte[] recordData)
A new record is added, the oldest record is deleted.
Note: CalypsoPo is filled with the provided input data.
sfi - the sfi to selectrecordData - the new record data to writejava.lang.IllegalArgumentException - if the command is inconsistentpublic final void prepareUpdateRecord(byte sfi,
int recordNumber,
byte[] recordData)
If the input data is shorter than the record size, only the first bytes will be overwritten.
Note: CalypsoPo is filled with the provided input data.
sfi - the sfi to selectrecordNumber - the record number to updaterecordData - the new record data. If length < RecSize, bytes beyond length are
left unchanged.java.lang.IllegalArgumentException - if record number is < 1java.lang.IllegalArgumentException - if the request is inconsistentpublic final void prepareWriteRecord(byte sfi,
int recordNumber,
byte[] recordData)
If the input data is shorter than the record size, only the first bytes will be overwritten.
Note: CalypsoPo is filled with the provided input data.
sfi - the sfi to selectrecordNumber - the record number to writerecordData - the data to overwrite in the record. If length < RecSize, bytes
beyond length are left unchanged.java.lang.IllegalArgumentException - if record number is < 1java.lang.IllegalArgumentException - if the request is inconsistentpublic final void prepareIncreaseCounter(byte sfi,
int counterNumber,
int incValue)
Note: CalypsoPo is filled with the provided input data.
counterNumber - >= 01h: Counters file, number of the counter. 00h: Simulated
Counter file.sfi - SFI of the file to select or 00h for current EFincValue - Value to add to the counter (defined as a positive int <= 16777215
[FFFFFFh])java.lang.IllegalArgumentException - if the decrement value is out of rangejava.lang.IllegalArgumentException - if the command is inconsistentpublic final void prepareDecreaseCounter(byte sfi,
int counterNumber,
int decValue)
Note: CalypsoPo is filled with the provided input data.
counterNumber - >= 01h: Counters file, number of the counter. 00h: Simulated
Counter file.sfi - SFI of the file to select or 00h for current EFdecValue - Value to subtract to the counter (defined as a positive int <= 16777215
[FFFFFFh])java.lang.IllegalArgumentException - if the decrement value is out of rangejava.lang.IllegalArgumentException - if the command is inconsistentpublic final void prepareSetCounter(byte sfi,
int counterNumber,
int newValue)
It builds an Increase or Decrease command and add it to the list of commands to be sent with
the next process command in order to set the target counter to the specified value.
The operation (Increase or Decrease) is selected according to whether the difference between
the current value and the desired value is negative (Increase) or positive (Decrease).
Note: it is assumed here that:
counterNumber - >= 01h: Counters file, number of the counter. 00h: Simulated
Counter file.sfi - SFI of the file to select or 00h for current EFnewValue - the desired value for the counter (defined as a positive int <=
16777215 [FFFFFFh])java.lang.IllegalArgumentException - if the desired value is out of range or if the command is
inconsistentCalypsoPoTransactionIllegalStateException - if the current counter value is unknown.public final void prepareCheckPinStatus()
The PIN status will made available in CalypsoPo after the execution of process command.
Adds it to the list of commands to be sent with the next process command.
See CalypsoPo.isPinBlocked() and CalypsoPo.getPinAttemptRemaining() methods.
CalypsoPoTransactionIllegalStateException - if the PIN feature is not available for this
PO.public final void prepareSvGet(PoTransaction.SvSettings.Operation svOperation, PoTransaction.SvSettings.Action svAction)
Once this command is processed, the result is available in CalypsoPo.
See the methods CalypsoPo.getSvBalance(), CalypsoPo.getSvLoadLogRecord()
()}, CalypsoPo.getSvDebitLogLastRecord(), CalypsoPo.getSvDebitLogAllRecords().
svOperation - informs about the nature of the intended operation: debit or reloadsvAction - the type of action: DO a debit or a positive reload, UNDO an undebit or a
negative reloadCalypsoPoTransactionIllegalStateException - if the SV feature is not available for this
PO.public final void prepareSvReload(int amount,
byte[] date,
byte[] time,
byte[] free)
Note #1: a communication with the SAM is done here.
Note #2: the key used is the reload key.
amount - the value to be reloaded, positive or negative integer in the range
-8388608..8388607date - 2-byte free valuetime - 2-byte free valuefree - 2-byte free valueCalypsoPoTransactionIllegalStateException - if the SV feature is not available for this
PO.public final void prepareSvReload(int amount)
Note #1: the optional SV additional data are set to zero.
Note #2: a communication with the SAM is done here.
Note #3: the key used is the reload key.
amount - the value to be reloaded, positive integer in the range 0..8388607 for a DO
action, in the range 0..8388608 for an UNDO action.CalypsoPoTransactionIllegalStateException - if the SV feature is not available for this
PO.public final void prepareSvDebit(int amount,
byte[] date,
byte[] time)
It consists in decreasing the current balance of the SV by a certain amount or canceling a previous debit according to the type operation chosen in when invoking the previous SV Get command.
Note #1: a communication with the SAM is done here.
Note #2: the key used is the reload key.
amount - the amount to be subtracted or added, positive integer in the range 0..32767 when
subtracted and 0..32768 when added.date - 2-byte free valuetime - 2-byte free valuepublic final void prepareSvDebit(int amount)
It consists in decreasing the current balance of the SV by a certain amount or canceling a previous debit.
Note #1: the optional SV additional data are set to zero.
Note #2: a communication with the SAM is done here.
Note #3: the key used is the reload key.The information fields such as date and time are set to 0. The extraInfo field propagated in Logs are automatically generated with the type of transaction and amount.
Note #4: operations that would result in a negative balance are forbidden (SV Exception raised).
Note #5: the key used is the debit key
amount - the amount to be subtracted or added, positive integer in the range 0..32767 when
subtracted and 0..32768 when added.public final void prepareSvReadAllLogs()
The SV transaction logs are contained in two files with fixed identifiers:
At the end of this reading operation, the data will be accessible in CalypsoPo in raw format
via the standard commands for accessing read files or in the form of dedicated objects (see
CalypsoPo.getSvLoadLogRecord() and CalypsoPo.getSvDebitLogAllRecords())
Once this command is processed, the result is available in CalypsoPo.
See the methods CalypsoPo.getSvBalance(), CalypsoPo.getSvLoadLogRecord()
()}, CalypsoPo.getSvDebitLogLastRecord(), CalypsoPo.getSvDebitLogAllRecords().
*
public final void prepareInvalidate()
This command is usually executed within a secure session with the SESSION_LVL_DEBIT key (depends on the access rights given to this command in the file structure of the PO).
CalypsoPoTransactionIllegalStateException - if the PO is already invalidatedpublic final void prepareRehabilitate()
This command is usually executed within a secure session with the SESSION_LVL_PERSO key (depends on the access rights given to this command in the file structure of the PO).
CalypsoPoTransactionIllegalStateException - if the PO is not invalidated