Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

TCP Server on Javacard and how to access it from mobile

JavaCard Applet Development Related Questions and Answers.
PeteSmithSIMs
Posts: 3
Joined: Mon Jan 17, 2022 12:52 pm
Points :94
Contact:

TCP Server on Javacard and how to access it from mobile

Post by PeteSmithSIMs » Mon Jan 17, 2022 4:04 pm

Hi all.

I hope this is the appropriate board and forum.

I've recently inherited quite an old codebase. It's a Javacard applet, running on a SIM card, which provides a service. It communicates outbound via SMS (which is redirected to a server via an SMSC) or TCP to a pre-defined IP address and port (which the server SMSC also knows about).

There is an area of code which seems to provide a local TCP server.

I believe that this was originally envisioned to allow an application running on the host mobile device to communicate with the applet, in order that the applet can send the application the same data as it would via SMS/TCP connection, but so that it could be routed via WIFI, and possibly augment the information returned by the service with additional information not available to the SIM card.

The setup block of code is
  1. parameters[idx++] = (byte) 0; // No bearer description
  2.  
  3. parameters[idx++] = (byte) 0; // No APN
  4.  
  5. parameters[idx++] = (byte) 3; // TCP server
  6.  
  7. idx = Util.setShort(parameters, idx, Configuration.LOCAL_COMMS_PORT); // This packs a 16 bit port number into 2 bytes.
  8.  
  9. parameters[idx++] = (byte) 0; // No destination address
LOCAL_COMMS_PORT is currently 0x1234.

There is a similar setup in the BIP connection code.

* Bearer is 2 (Default), not 0.
* APN is filled from an array (from a configuration object)
* "TCP server" is 2, not 3.
* Port number is set from a different short.
* The destination address is set from an array (from a config object)

The resulting array is used to open a channel by calling the Proactive Handler with the type 0x40.

I know that this setup works for outbound (BIP) connections, as I'm receiving packets of data at the server, so I'm assuming that the setup for Local comms works as well.

The problem is, that I have absolutely 100% no idea where to progress from here. The devs who wrote this code all left years ago. It's possible that this code was written from a purely theoretical point of view.

I've done a small amount of looking round. What I have found so far seems to point to this sort of implementation not having an implicit IP address. It also looks like I'm going to have an issue (even if I can find an address which works) talking to a raw TCP socket via Android. I think I might have to wrap the comms channel in a very crude HTTP wrapper, and run a long poll with say a 5 minute timeout, so GET from the server, and wait. If anything happens in 5 minutes, it gets the response, and if not, it times out and tries again.

If anyone's done this, if they could give me some pointers, even if it's terminology to use, then I'd be eternally grateful. If someone could say "Ah yeah, you need the xyz widget", I could then go and investigate xyz widgets.

Alternatively, if this just isn't possible I'd welcome alternatives. I believe that under Android, I can communicate using APDUs using the SEEK library. There doesn't seem to be an equivalent for iOS, for security reasons.

I'm a veteran dev. I've done a lot of Java, and a lot of embedded, but nothing quite like Javacard!

Many thanks.

Pete.

mbsysde99
Posts: 40
Joined: Tue Oct 24, 2017 1:10 pm
Points :484
Contact:

Re: TCP Server on Javacard and how to access it from mobile

Post by mbsysde99 » Sun Feb 06, 2022 7:02 am

If you want your `javacard` to be read by your `android phone`, you can create an `android program` as `a host` on your `android phone`. The `Java card` can be connected to an `Android phone` via an `NFC reader`. So your `Android phone must support NFC reader`. If your Android phone does not have an `internal NFC reader`, you can buy an `external NFC Reader` that is connected to `USB of android phone`.

You can send apdu from android phone to the card and receive apdu replies sent by the card on your anroid phone after the nfc connection is connected.

Look at https://developer.android.com/guide/top ... tivity/nfc for NFC on Android

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 36 guests

JavaCard OS : Disclaimer