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.

How to use jsr177 to access smart card

JavaCard Applet Development Related Questions and Answers.
notuo
Posts: 12
Joined: Thu Jan 14, 2016 4:45 am
Points :143
Contact:

How to use jsr177 to access smart card

Post by notuo » Sun Sep 24, 2017 11:10 pm

I would like to use jsr177 to access smart card by sending APDU. But I don't know how APDUs are sent to my smartard? Does jsr177 also use similar pc/sc? Any help is greatly appreciated.

roundtable
Posts: 18
Joined: Mon Sep 18, 2017 9:52 pm
Points :240
Contact:

Re: How to use jsr177 to access smart card

Post by roundtable » Tue Oct 10, 2017 1:35 am

please show us more info about jsr177, URL or other way that we can download it.

kuafu
Posts: 317
Joined: Thu Jun 25, 2015 2:09 am
Points :4551
Contact:

Re: How to use jsr177 to access smart card

Post by kuafu » Tue Oct 10, 2017 3:33 am

Connect the card reader and the card and reset it。

Code: Select all

 /**
  *connectpcsc.java

  */


import java.util.List;

import javax.smartcardio.CardTerminal;
import javax.smartcardio.TerminalFactory;


public class connectpcsc {
 /**
  * main function, listing all the PC/SC readers connected to your PC
  */
 public static void main(String[] args) {

  // show the list of available terminals
  TerminalFactory factory = TerminalFactory.getDefault();
 
  // list of readers (empty)
  List<CardTerminal> terminals;
  try {
   // get list of readers form the terminal
   terminals = factory.terminals().list();
   
   // print list of readers to the console.
   System.out.println(terminals.toString());

  } catch (Exception e) {
   // Print Stack-Trace in case of an error
   e.printStackTrace();
  }
 }
}





Connect the card reader and card to send the APDU command

Code: Select all

import java.util.List;

import javax.smartcardio.Card;
import javax.smartcardio.CardChannel;
import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
import javax.smartcardio.TerminalFactory;

public class GetStatus {
 public static void main(String[] args) {
 TerminalFactory factory = TerminalFactory.getDefault();
   try {
    List<CardTerminal> terminal = factory.terminals().list();
    System.out.println("terminal:" + terminal);
   
   CardTerminal ter = terminal.get(0);
   
         // establish a connection with the card
         Card card = ter.connect("T=0");
         System.out.println("card: " + card);
         CardChannel channel = card.getBasicChannel();
         
         ResponseAPDU r = channel.transmit(new CommandAPDU(160, 242, 0, 0, 22)); //A0 F2 00 00 16   
         System.out.println("response: " + r.toString());         
         for(int j=0; j<8; j++) {
          System.out.print(Integer.toHexString( (int)((r.getData()[j]+256) % 256)) + " ");
         }

         System.out.print("\n");

         for(int j=0; j<card.getATR().getBytes().length; j++) {
          System.out.print(Integer.toHexString( (int)((card.getATR().getBytes()[j]+256) % 256)) + " ");
         }

         // disconnect
         card.disconnect(false);
   } catch (CardException e) {
    // TODO Auto-generated catch block
    System.out.println("connection erro,or card not inserted.");
   }
 }
}



More detail
http://docs.oracle.com/javase/6/docs/jre/api/security/smartcardio/spec/javax/smartcardio/package-summary.html
well

kuafu
Posts: 317
Joined: Thu Jun 25, 2015 2:09 am
Points :4551
Contact:

Re: How to use jsr177 to access smart card

Post by kuafu » Tue Oct 10, 2017 3:43 am

notuo wrote:I would like to use jsr177 to access smart card by sending APDU. But I don't know how APDUs are sent to my smartard? Does jsr177 also use similar pc/sc? Any help is greatly appreciated.

https://stackoverflow.com/questions/891341/how-to-use-apdu-in-jsr-177-to-access-the-sim-card

Mostly, JSR 177 is supposed to be used to extract the certificate that is on the SIM so you can encrypt/decrypt/sign data in a way that your MNO likes.

The difficulty in finding documentation comes from so few handset manufacturers having included a full JSR177 implementation in their phone.

That, in turn, presumably comes from the huge amount of external, security-related specs to read and understand before the JSR177 spec itself makes sense if you're not a cryptography protocols expert.

The TCK sources and supplemental Symbian/Nokia test code would be a good place to look but, unfortunately, none of that has been open-sourced yet.

Common commands like changing the SIM PIN code basically require an understanding of the binary protocol itself. Simply appending the correct sequence of bytes to an APDU GCF url will get it executed if the JSR177 implementation itself is correct.

If you have only looked at the Sun JavaME SDK, you should probably have a look at the APDU MIDlet example in the latest Series60 SDK and added documentation in Nokia's Java Developer's Library.
well

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: Bing [Bot] and 21 guests

JavaCard OS : Disclaimer