1 /** 2 * --------- 3 * |.##> <##.| Open Smart Card Development Platform (www.openscdp.org) 4 * |# #| 5 * |# #| Copyright (c) 1999-2010 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 Script to populate a certificate store from a directory full of certificates 25 */ 26 27 28 load("cvcertstore.js"); 29 30 31 32 var inputdir = "testcvcs"; 33 var outputdir = "testcvcs/certstore"; 34 35 36 function listCertificates(dir) { 37 var f = new java.io.File(dir); 38 var files = f.list(); 39 var result = []; 40 41 for (var i = 0; i < files.length; i++) { 42 var s = new String(files[i]); 43 var n = s.match(/\.(cvcert|CVCERT)$/); 44 if (n) { 45 var bin = CVCertificateStore.loadBinaryFile(dir + "/" + s); 46 var cvc = new CVC(bin); 47 result.push(cvc); 48 } 49 } 50 return result; 51 } 52 53 54 55 var inputdir = GPSystem.mapFilename(inputdir, GPSystem.CWD); 56 var outputdir = GPSystem.mapFilename(outputdir, GPSystem.CWD); 57 58 var crypto = new Crypto(); 59 60 var store = new CVCertificateStore(outputdir); 61 var certlist = listCertificates(inputdir); 62 63 for (var i = 0; i < certlist.length; i++) { 64 print(certlist[i]); 65 } 66 67 var unprocessed = store.insertCertificates2(crypto, certlist, true); 68 69 if (unprocessed.length > 0) { 70 print("The following certificates could not be processed:"); 71 for (var i = 0; i < unprocessed.length; i++) { 72 print(unprocessed[i]); 73 } 74 } 75