Class TKSmartCard

  • All Implemented Interfaces:
    NSObject

    public class TKSmartCard
    extends NSObject
    Represents SmartCard inserted in the slot. Once the card is physically removed from the slot, the session object is invalid and will always fail the operation invoked on it. In order to communicate with the card, an exclusive session must be established.
    • Constructor Detail

      • TKSmartCard

        protected TKSmartCard​(org.moe.natj.general.Pointer peer)
    • Method Detail

      • accessInstanceVariablesDirectly

        public static boolean accessInstanceVariablesDirectly()
      • allocWithZone

        public static java.lang.Object allocWithZone​(org.moe.natj.general.ptr.VoidPtr zone)
      • allowedProtocols

        public long allowedProtocols()
        Bitmask containing allowed protocols to be used when communicating with the card. This property is consulted only during connection to the card, changes are not propagated to already connected session. By default, any protocol can be used.
      • automaticallyNotifiesObserversForKey

        public static boolean automaticallyNotifiesObserversForKey​(java.lang.String key)
      • beginSessionWithReply

        public void beginSessionWithReply​(TKSmartCard.Block_beginSessionWithReply reply)
        Begins session with the card. When session exists, other requests for sessions from other card objects to the same card are blocked. Session is reference-counted, the same amount of 'end' calls must be done to really terminate the session. Note that finishing session does not automatically mean that the card is disconnected; it only happens when another session from different card object is requested.
        Parameters:
        success - Signals whether session was successfully started.
        error - More information about error preventing the transaction to start
      • cancelPreviousPerformRequestsWithTarget

        public static void cancelPreviousPerformRequestsWithTarget​(java.lang.Object aTarget)
      • cancelPreviousPerformRequestsWithTargetSelectorObject

        public static void cancelPreviousPerformRequestsWithTargetSelectorObject​(java.lang.Object aTarget,
                                                                                 org.moe.natj.objc.SEL aSelector,
                                                                                 java.lang.Object anArgument)
      • cla

        public byte cla()
        CLA byte which will be used for sendIns: APDU transmits. Default value is 0x00.
      • classFallbacksForKeyedArchiver

        public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
      • classForKeyedUnarchiver

        public static org.moe.natj.objc.Class classForKeyedUnarchiver()
      • context

        public java.lang.Object context()
        User-specified context kept as long as the card is powered. Once the card is removed or another TKSmartCard object opens session, this property is automatically set to nil.
      • currentProtocol

        public long currentProtocol()
        Protocol used for communication with the SmartCard. If no card session is established, TKSmartCardProtocolNone is set.
      • debugDescription_static

        public static java.lang.String debugDescription_static()
      • description_static

        public static java.lang.String description_static()
      • endSession

        public void endSession()
        Terminates the transaction. If no transaction is pending any more, the connection will be closed if there is another session in the system waiting for the transaction.
      • hash_static

        public static long hash_static()
      • inSessionWithErrorExecuteBlock

        public boolean inSessionWithErrorExecuteBlock​(org.moe.natj.general.ptr.Ptr<NSError> error,
                                                      TKSmartCard.Block_inSessionWithErrorExecuteBlock block)
        Synchronous variant of session creation. Begins the session, executes given block and ends session.
        Parameters:
        error - Error receiving more information when transaction failed to start or block failed for some reason.
        block - Block to be executed when the session was successfully begun.
        Returns:
        Returns YES if the session was successfully begun and block returned YES, otherwise NO.
      • instanceMethodSignatureForSelector

        public static NSMethodSignature instanceMethodSignatureForSelector​(org.moe.natj.objc.SEL aSelector)
      • instancesRespondToSelector

        public static boolean instancesRespondToSelector​(org.moe.natj.objc.SEL aSelector)
      • isSubclassOfClass

        public static boolean isSubclassOfClass​(org.moe.natj.objc.Class aClass)
      • keyPathsForValuesAffectingValueForKey

        public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey​(java.lang.String key)
      • new_objc

        public static java.lang.Object new_objc()
      • resolveClassMethod

        public static boolean resolveClassMethod​(org.moe.natj.objc.SEL sel)
      • resolveInstanceMethod

        public static boolean resolveInstanceMethod​(org.moe.natj.objc.SEL sel)
      • sendInsP1P2DataLeReply

        public void sendInsP1P2DataLeReply​(byte ins,
                                           byte p1,
                                           byte p2,
                                           NSData requestData,
                                           NSNumber le,
                                           TKSmartCard.Block_sendInsP1P2DataLeReply reply)
        Transmits APDU to the card and returns response. Asynchronous high level variant of command for transmitting APDU to the card. Handles all ISO7816-4 APDU cases translation to proper sequences according to used protocol. Consults useExtendedAPDU and useCommandChaining properties and uses these modes whenever appropriate and beneficial for sending requested APDU request.
        Parameters:
        ins - INS code of the APDU
        p1 - P1 code of the APDU
        p2 - P2 code of the APDU
        requestData - Data field of the APDU, or nil if no input data field should be present (i.e case1 or case2 APDUs). Length of the data serves as Lc field of the APDU.
        le - Expected number of bytes to be returned, or nil if no output data are expected (i.e. case1 or case3 APDUs). To get as much bytes as card provides, pass @0.
        replyData - Block of returned data without SW1SW2 bytes, or nil if an error occured.
        sw - SW1SW2 result code, first two bytes of returned card's reply.
        error - Contains error details when nil is returned. Specific error is also filled in if there was no communication error, but card returned other SW code than 0x9000.
      • sendInsP1P2DataLeSwError

        public NSData sendInsP1P2DataLeSwError​(byte ins,
                                               byte p1,
                                               byte p2,
                                               NSData requestData,
                                               NSNumber le,
                                               org.moe.natj.general.ptr.CharPtr sw,
                                               org.moe.natj.general.ptr.Ptr<NSError> error)
        Transmits APDU to the card and returns response. Synchronous high level variant of command for transmitting APDU to the card. Handles all ISO7816-4 APDU cases translation to proper sequences according to used protocol. Should be used in block passed to -[TKSmartCard inSessionWithError:executeBlock:] method.
        Parameters:
        ins - INS code of the APDU
        p1 - P1 code of the APDU
        p2 - P2 code of the APDU
        data - Data field of the APDU. Length of the data serves as Lc field of the APDU
        le - Expected number of bytes to be returned, or nil if no output data are expected (i.e. case1 or case3 APDUs). To get as much bytes as card provides, pass @0.
        sw - On output, filled with SW1SW2 result code
        error - Contains error details when nil is returned. Specific error is also filled in if there was no communication error, but card returned other SW code than 0x9000.
        Returns:
        Returned data field, excluding SW status bytes. If an error occured, returns nil.
      • sensitive

        public boolean sensitive()
        Flag indicating whether card session should be considered as sensitive. Sensitive session always gets card after reset before communicating with it and never leaves card without reset to be used by another SmartCard object. This might be important in case that card session contain some important state which should not leak to another SmartCard object (possibly running in another, foreign application). Default is NO.
      • setAllowedProtocols

        public void setAllowedProtocols​(long value)
        Bitmask containing allowed protocols to be used when communicating with the card. This property is consulted only during connection to the card, changes are not propagated to already connected session. By default, any protocol can be used.
      • setCla

        public void setCla​(byte value)
        CLA byte which will be used for sendIns: APDU transmits. Default value is 0x00.
      • setContext

        public void setContext​(java.lang.Object value)
        User-specified context kept as long as the card is powered. Once the card is removed or another TKSmartCard object opens session, this property is automatically set to nil.
      • setSensitive

        public void setSensitive​(boolean value)
        Flag indicating whether card session should be considered as sensitive. Sensitive session always gets card after reset before communicating with it and never leaves card without reset to be used by another SmartCard object. This might be important in case that card session contain some important state which should not leak to another SmartCard object (possibly running in another, foreign application). Default is NO.
      • setUseCommandChaining

        public void setUseCommandChaining​(boolean value)
        Flag indicating whether command chaining of APDU with data field longer than 255 bytes can be used. It is automatically enabled when card announces that command chaining is supported in its ATR. However, caller can explicitly override this decision.
      • setUseExtendedLength

        public void setUseExtendedLength​(boolean value)
        Flag indicating whether extended length APDUs should be used. It is automatically enabled only when used slot supports transmitting extended length commands and card announces that extended length APDU are supported in its ATR. However, caller can explicitly override this decision.
      • setVersion_static

        public static void setVersion_static​(long aVersion)
      • slot

        public TKSmartCardSlot slot()
        Slot in which is this card inserted.
      • superclass_static

        public static org.moe.natj.objc.Class superclass_static()
      • transmitRequestReply

        public void transmitRequestReply​(NSData request,
                                         TKSmartCard.Block_transmitRequestReply reply)
        Transmits raw command to the card. This call is allowed only inside session.
        Parameters:
        request - Request part of APDU
        reponse - Response part of APDU, or nil if communication with the card failed
        error - Error details when communication with the card failed
      • useCommandChaining

        public boolean useCommandChaining()
        Flag indicating whether command chaining of APDU with data field longer than 255 bytes can be used. It is automatically enabled when card announces that command chaining is supported in its ATR. However, caller can explicitly override this decision.
      • useExtendedLength

        public boolean useExtendedLength()
        Flag indicating whether extended length APDUs should be used. It is automatically enabled only when used slot supports transmitting extended length commands and card announces that extended length APDU are supported in its ATR. However, caller can explicitly override this decision.
      • userInteractionForSecurePINChangeWithPINFormatAPDUCurrentPINByteOffsetNewPINByteOffset

        public TKSmartCardUserInteractionForSecurePINChange userInteractionForSecurePINChangeWithPINFormatAPDUCurrentPINByteOffsetNewPINByteOffset​(TKSmartCardPINFormat PINFormat,
                                                                                                                                                   NSData APDU,
                                                                                                                                                   long currentPINByteOffset,
                                                                                                                                                   long newPINByteOffset)
        Creates a new user interaction object for secure PIN change using the SmartCard reader facilities (typically a HW keypad). [@note] This interaction is only allowed within a session.
        Parameters:
        PINFormat - PIN format descriptor.
        APDU - Predefined APDU in which the SmartCard reader fills in the PIN(s).
        currentPINByteOffset - Offset in bytes within APDU data field to mark a location of a PIN block for filling in the current PIN.
        newPINByteOffset - Offset in bytes within APDU data field to mark a location of a PIN block for filling in the new PIN.
        Returns:
        A new user interaction object, or nil if this feature is not supported by the SmartCard reader. After the interaction has been successfully completed the operation result is available in the result properites.
      • userInteractionForSecurePINVerificationWithPINFormatAPDUPINByteOffset

        public TKSmartCardUserInteractionForSecurePINVerification userInteractionForSecurePINVerificationWithPINFormatAPDUPINByteOffset​(TKSmartCardPINFormat PINFormat,
                                                                                                                                        NSData APDU,
                                                                                                                                        long PINByteOffset)
        Creates a new user interaction object for secure PIN verification using the SmartCard reader facilities (typically a HW keypad). [@note] This interaction is only allowed within a session.
        Parameters:
        PINFormat - PIN format descriptor.
        APDU - Predefined APDU in which the SmartCard reader fills in the PIN.
        PINByteOffset - Offset in bytes within APDU data field to mark a location of a PIN block for filling in the entered PIN (currently unused, must be 0).
        Returns:
        A new user interaction object, or nil if this feature is not supported by the SmartCard reader. After the interaction has been successfully completed the operation result is available in the result properites.
      • valid

        public boolean valid()
        Flag indicating whether card is valid, i.e. it was not removed from the reader. Use Key-Value-Observing to be notified about card removal.
      • version_static

        public static long version_static()