OpenCard Framework Application Development by Vesna Hassler and Oliver Fodor Listing One OpenCard.services = samples.simplestring.SimpleStringCardServiceFactory OpenCard.terminals = dk.itplus.smartcard.terminal.litronic210. LitronicCardTerminalFactory|Litronic210|Litronic210|COM1 Listing Two private void setString(APDU apdu) { buffer = apdu.getBuffer(); // receive data from terminal byte size = (byte)(apdu.setIncomingAndReceive()); byte index; TheBuffer[0] = size; // store string and its length Util.arrayCopy(buffer, ISO.OFFSET_CDATA, TheBuffer, (short)1, (short)size); return; } Listing Three private void getString(APDU apdu) { buffer = apdu.getBuffer(); byte numBytes = buffer[ISO.OFFSET_LC]; if (numBytes == 0) ISOException.throwIt((short)(SW_WRONG_LENGTH + TheBuffer[0])); apdu.setOutgoing(); apdu.setOutgoingLength(numBytes); Util.arrayCopy(TheBuffer,(short)1,buffer,(short)0,(short)numBytes); apdu.sendBytes((short)0,(short)numBytes); return; } Listing Four public void selectApplet() throws CardServiceException { try { allocateCardChannel(); sendAPDU(selectRoot); sendAPDU(selectApp); } catch(Exception e) { e.printStackTrace(); throw new CardServiceException(); } finally { releaseCardChannel(); } appletSelected = true; return; Listing Five private ResponseAPDU sendAPDU(byte[] apdu) throws CardTerminalException { // Set up the command APDU CommandAPDU commandAPDU = new CommandAPDU(apdu); ResponseAPDU responseAPDU=getCardChannel().sendCommandAPDU(commandAPDU); return (responseAPDU); } Listing Six public SimpleStringCardServiceFactory() { try { cyberFlexCID = new CardID (cyberFlexATR); } catch ( Exception e ) { } } Listing Seven // register card service with OCF static { services_.addElement(SimpleStringCardService.class); } Listing Eight protected Enumeration cardServiceClasses(CardID cid) { return services_.elements(); } public boolean knows(CardID cardID) { // check whether the factory knows the smartcard OS if (cardID.equals(cyberFlexCID)) { return true; } else { return false; } } Listing Nine // initialize OCF SmartCard.start(); CardRequest cr = new CardRequest(SimpleStringCardService.class); // wait for card supporting SimpleStringCardService SmartCard sc = SmartCard.waitForCard(cr); // instantiate card service SimpleStringCardService ssp = (SimpleStringCardService)sc. getCardService(SimpleStringCardService.class, true); 3