1 /**
  2  *  ---------
  3  * |.##> <##.|  Open Smart Card Development Platform (www.openscdp.org)
  4  * |#       #|  
  5  * |#       #|  Copyright (c) 1999-2009 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  * @fileoverview Do a complete session with PACE, TA and CA
 25  */
 26 
 27 load("eac20.js");
 28 
 29 var can = "164236";
 30 
 31 
 32 var crypto = new Crypto();
 33 
 34 var certstorepath = GPSystem.mapFilename("cvc", GPSystem.CWD);
 35 
 36 var certstore = new CVCertificateStore(certstorepath);
 37 
 38 
 39 // var card = new EAC20Sim();
 40 var card = new Card(_scsh3.reader);
 41 
 42 card.reset(Card.RESET_COLD);
 43 
 44 var chat = new ASN1(0x7F4C, 
 45 						new ASN1(ASN1.OBJECT_IDENTIFIER, new ByteString(PACE.id_IS, OID)),
 46 						new ASN1(0x53, new ByteString("23", HEX))
 47 					);
 48 
 49 var eac = new EAC20(crypto, card);
 50 
 51 print("Reading EF.CardInfo...");
 52 eac.readCardInfo();
 53 
 54 print("Performing PACE...");
 55 var pwd = new ByteString(can, ASCII);
 56 var sm = eac.performPACE(0, EAC20.ID_CAN, pwd, chat);
 57 
 58 print("Performing TA...");
 59 var car = eac.getTrustAnchorCAR(false);
 60 
 61 var cvcchain = certstore.getCertificateChainFor(car);
 62 
 63 eac.verifyCertificateChain(cvcchain);
 64 
 65 // Get key for terminal certificate
 66 var termkey = certstore.getTerminalKeyFor(car);
 67 
 68 var ad = new ASN1(0x67);
 69 
 70 eac.prepareChipAuthentication(0);
 71 
 72 eac.performTerminalAuthentication(termkey, ad.getBytes());
 73 
 74 print("Reading EF.CardSecurity...");
 75 eac.readCardSecurity();
 76 
 77 print("Performing CA...");
 78 eac.performChipAuthentication();
 79 
 80 print("Reading using secure messaging...");
 81 var mf = eac.mf;
 82 var ef = new CardFile(mf, ":011C");
 83 var data = ef.readBinary(0);
 84 print(data);
 85 
 86