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 Request certificate from CVCA
 25  */
 26 
 27 load("../lib/taconnection.js");
 28 load("../cvcertstore.js");
 29 
 30 
 31 /**
 32  * Prompt for a value from persistent configuration
 33  * 
 34  * The new value is stored a configuration item. Backslashes are properly escaped.
 35  * 
 36  * @param {String} text the text to display
 37  * @param {String} id the configuration item
 38  * @param {String} defvalue the default value
 39  * @return the selected value
 40  */
 41 function prompt(text, id, defvalue, filter) {
 42 	if (typeof(_scsh3[id]) != "undefined") {
 43 		var value = _scsh3[id];
 44 	} else {
 45 		var value = defvalue;
 46 	}
 47 	var value = Dialog.prompt(text, value, null, filter);
 48 	if (value == null) {
 49 		throw new Error("User abort");
 50 	} else {
 51 		value = value.replace(/\\/g, "/");
 52 		_scsh3.setProperty(id, value);
 53 	}
 54 	return value;
 55 }
 56 
 57 
 58 
 59 var url = prompt("Enter the URL of the CVCA service endpoint", "cvcaurl", "http://localhost:8080/se/cvca");
 60 var reqfile = prompt("Select request", "reqfilename", "c:/data", "*.cvreq");
 61 
 62 var reqbin = CVCertificateStore.loadBinaryFile(reqfile);
 63 
 64 var req = new CVC(reqbin);
 65 
 66 var cc = new TAConnection(url, true);
 67 cc.verbose = true;
 68 
 69 var certlist = cc.getCACertificates();
 70 
 71 print(req);
 72 var certs = cc.requestCertificate(req.getBytes());
 73 
 74 var dir = reqfile.substr(0, reqfile.lastIndexOf("/") + 1);
 75 
 76 for (var i = 0; i < certs.length; i++) {
 77 	var cvc = new CVC(certs[i]);
 78 	print(cvc);
 79 	var filename = dir + cvc.getCHR().toString() + ".cvcert";
 80 	CVCertificateStore.saveBinaryFile(filename, cvc.getBytes());
 81 }
 82