1 /** 2 * --------- 3 * |.##> <##.| SmartCard-HSM Support Scripts 4 * |# #| 5 * |# #| Copyright (c) 2011-2012 CardContact Software & System Consulting 6 * |'##> <##'| Andreas Schwier, 32429 Minden, Germany (www.cardcontact.de) 7 * --------- 8 * 9 * Consult your license package for usage terms and conditions. 10 * 11 * @fileoverview Store X.509 certificate on the SmartCard 12 */ 13 14 15 // Load classes 16 load("../lib/smartcardhsm.js"); 17 load("../lib/hsmkeystore.js"); 18 19 // Card access 20 var card = new Card(); 21 22 // Reset card 23 card.reset(Card.RESET_COLD); 24 25 // Select SmartCard-HSM application 26 card.sendApdu(0x00, 0xA4, 0x04, 0x04, new ByteString("E8 2B 06 01 04 01 81 C3 1F 02 01", HEX), [0x9000]); 27 28 // Create card access object 29 var sc = new SmartCardHSM(card); 30 31 // Verify user PIN 32 var userPIN = Dialog.prompt("Please enter user PIN for SmartCard-HSM", "648219"); 33 assert(userPIN != null); 34 sc.verifyUserPIN(new ByteString(userPIN, ASCII)); 35 36 // Key store front-end 37 var hsmks = new HSMKeyStore(sc); 38 sc.enumerateKeys(); 39 40 // Keypair label 41 var eMailAddress = Dialog.prompt("Please enter your e-mail address", ""); 42 var label = eMailAddress; 43 var key = sc.getKey(label); 44 45 // openssl x509 -outform der -in certificate.pem -out certificate.der 46 47 // Select certificate (*.der) for storing on the SmartCard 48 var hsmks = new HSMKeyStore(sc); 49 var certder = Dialog.prompt("Select X.509 certificate", "", null, "*.der"); 50 var cert = new X509(certder); 51 hsmks.storeEndEntityCertificate(label, cert); 52 print("X.509 certificate written to SmartCard...");