1 /*
  2  *  ---------
  3  * |.##> <##.|  Open Smart Card Development Platform (www.openscdp.org)
  4  * |#       #|  
  5  * |#       #|  Copyright (c) 1999-2006 CardContact Software & System Consulting
  6  * |'##> <##'|  Andreas Schwier, 32429 Minden, Germany (www.cardcontact.de)
  7  *  --------- 
  8  *
  9  *  This file is part of OpenSCDP.
 10  *
 11  *  OpenSCDP is free software; you can redistribute it and/or modify
 12  *  it under the terms of the GNU General Public License version 2 as
 13  *  published by the Free Software Foundation.
 14  *
 15  *  OpenSCDP is distributed in the hope that it will be useful,
 16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18  *  GNU General Public License for more details.
 19  *
 20  *  You should have received a copy of the GNU General Public License
 21  *  along with OpenSCDP; if not, write to the Free Software
 22  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 23  */
 24 
 25 //
 26 // Example how to use Java classes from within scripts
 27 // Perform verification with PIN input on the card reader
 28 //
 29 
 30 // 1. Get CardTerminalRegistry from OpenCard Framework
 31 
 32 var ctr = Packages.opencard.core.terminal.CardTerminalRegistry.getRegistry();
 33 
 34 // 2. Get CardTerminal instance for a given name
 35 
 36 if (_scsh3.reader) {
 37 	var ct = ctr.cardTerminalForName(_scsh3.reader);
 38 } else {
 39 	// Use default if no reader is configured
 40 	var ct = ctr.cardTerminalForName("MCT");
 41 }
 42 
 43 // 3. Create command to perform
 44 //      Control Byte | Offset | APDU
 45 
 46 var ctp = new ByteString("4206002000010824FFFFFFFFFFFFFF", HEX);
 47 //or: var ctp = new ByteString("420600200001", HEX);
 48 var ctpdo = new ASN1(0x52, ctp);
 49 
 50 // 4. Prepare message to display (TLV object with tag '50')
 51 
 52 var text = "Please enter PIN";
 53 var displayObject = new ASN1(0x50, new ByteString(text, ASCII));
 54 
 55 // 5. Create display APDU (see MKT specification, part 4, chapter 6.2.3
 56 // CLA = 20, INS = 18, P1 = 01 (Slot#1), P2 = 00 (PIN-PAD)
 57 
 58 var capdu = new ByteBuffer("20180100", HEX);
 59 capdu.append(ctpdo.size + displayObject.size);
 60 capdu.append(ctpdo.getBytes());
 61 capdu.append(displayObject.getBytes());
 62 
 63 // 5. Send to card reader
 64 
 65 print(capdu.toByteString());
 66 var response = ct.sendTerminalCommand(capdu.toByteString());
 67 
 68 print(response);
 69