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 * MuscleCard Initialization 25 * 26 * After loading the applet into a JavaCard, the data structure needs to be 27 * initialized. This is done through an undocumented setup APDU. 28 * 29 * The contents of the APDU has been reverse engineered from the applet's code 30 */ 31 32 33 load("tools.js"); 34 35 var card = new Card(_scsh3.reader); 36 card.reset(Card.RESET_COLD); 37 38 // Select Applet 39 card.sendApdu(0x00, 0xA4, 0x04, 0x00, mcaid, [0x9000]); 40 41 // Try MSCGetStatus 42 resp = card.sendApdu(0xB0, 0x3C, 0x00, 0x00, 0x05); 43 44 if (card.SW == 0x9C05) { 45 print("Applet not initialized"); 46 47 // Initialize applet 48 49 var initstr = new ByteBuffer(); 50 51 var defaultPwd = new ByteString("Muscle00", ASCII); 52 var PIN0 = new ByteString("12345678", ASCII); 53 var UPIN0 = new ByteString("12345678", ASCII); 54 var PIN1 = new ByteString("12345678", ASCII); 55 var UPIN1 = new ByteString("12345678", ASCII); 56 57 // The applet verifies the default PIN0 value,... 58 initstr.append(defaultPwd.length); 59 initstr.append(defaultPwd); 60 61 // ...then sets PIN 0,... 62 initstr.append(0x10); // PIN0 Tries 63 initstr.append(0x10); // UPIN0 Tries 64 initstr.append(PIN0.length); 65 initstr.append(PIN0); 66 initstr.append(UPIN0.length); 67 initstr.append(UPIN0); 68 69 // ...PIN1,... 70 initstr.append(0x10); // PIN1 Tries 71 initstr.append(0x10); // UPIN1 Tries 72 initstr.append(PIN1.length); 73 initstr.append(PIN1); 74 initstr.append(UPIN1.length); 75 initstr.append(UPIN1); 76 77 // ... <unused>, ... 78 initstr.append(new ByteString("0000", HEX)); 79 80 // ... memory size for keys and objects and ... 81 initstr.append(new ByteString("1000", HEX)); // Memory Size 82 83 // ... access control settings for creating objects, keys and PINs 84 initstr.append(new ByteString("000000", HEX)); // ACL for Object, Key and PIN 85 86 print(initstr); 87 88 card.sendApdu(0xB0, 0x2A, 0x00, 0x00, initstr.toByteString()); 89 print(card.SW.toString(HEX)); 90 91 // Try MSCGetStatus 92 resp = card.sendApdu(0xB0, 0x3C, 0x00, 0x00, 0x05); 93 } else { 94 print("MuscleCard Applet already initialized"); 95 } 96 97 if (card.SW1 == 0x61) { 98 var rem = card.sendApdu(0x00, 0xC0, 0x00, 0x00, card.SW1); 99 resp = resp.concat(rem); 100 } 101 102 printStatus(resp); 103