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 Tool to decode and dump CVC certificates 25 */ 26 27 28 requires("3.6.733"); 29 30 load("cvc.js"); 31 32 33 34 /** 35 * Creates a simple CVCExplorer object 36 * 37 * @class Class providing for a simple explorer for CV-Certificates according to EAC specification. 38 */ 39 function CVCExplorer() { 40 } 41 42 43 44 // Some static strings 45 CVCExplorer.FILESTR = "Open File..."; 46 CVCExplorer.DUMPSTR = "Dump"; 47 CVCExplorer.REMOVESTR = "Remove"; 48 49 50 51 52 /** 53 * Loads a binary file from disk 54 * 55 * @param {String} filename the fully qualified file name 56 * @return the binary content 57 * @type ByteString 58 */ 59 CVCExplorer.loadBinaryFile = function(filename) { 60 // Open stream 61 var f = new java.io.FileInputStream(filename); 62 63 // Determine file size 64 var flen = f.available(); 65 66 // Allocate native byte array 67 var bs = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, flen); 68 69 // Read into byte array 70 var len = f.read(bs); 71 72 // Allocate JavaScript ByteBuffer from native/wrapped byte array 73 var bb = new ByteBuffer(bs); 74 75 // Convert to JavaScript ByteString 76 var data = bb.toByteString(); 77 78 return data; 79 } 80 81 82 83 /** 84 * Dump certificate content 85 * 86 * @param {CVC} cvc the certificate to dump 87 */ 88 CVCExplorer.dumpCertificate = function(cvc) { 89 print("-----8<----------8<----------8<----------8<----------8<----------8<----------8<----------8<-----"); 90 print(cvc); 91 var list = cvc.getRightsAsList(); 92 for (var i = 0; i < list.length; i++) { 93 print(" " + list[i]); 94 } 95 print(cvc.getASN1()); 96 } 97 98 99 100 /** 101 * Selects a file with a file dialog, creates the associated node in the outline 102 * and dumps the certificate contents. 103 * 104 */ 105 CVCExplorer.prototype.selectFile = function() { 106 var filename = _scsh3.lastcvc; 107 if (!filename) { 108 filename = ""; 109 } 110 111 var select = Dialog.prompt("Select CVC file", filename, null, "*.cvcert"); 112 113 if (select != null) { 114 _scsh3.setProperty("lastcvc", select.replace(/\\/g, "/")); 115 116 var bin = CVCExplorer.loadBinaryFile(select); 117 118 var cvc = new CVC(bin); 119 cvc.decorate(); 120 121 var fn = new OutlineNode(select); 122 fn.cvc = cvc; 123 fn.setContextMenu([CVCExplorer.DUMPSTR, CVCExplorer.REMOVESTR]); 124 fn.setUserObject(this); 125 126 this.node.insert(fn); 127 fn.insert(cvc.getASN1()); 128 129 CVCExplorer.dumpCertificate(cvc); 130 } 131 } 132 133 134 135 /** 136 * Action listener called when a entry in the context menu is selected 137 * 138 * @param {OutlineNode} source the object to which the context menu is associated 139 * @param {String} action the action selected from the context menu 140 */ 141 CVCExplorer.prototype.actionListener = function(source, action) { 142 143 switch(action) { 144 case CVCExplorer.FILESTR: 145 this.selectFile(); 146 break; 147 case CVCExplorer.DUMPSTR: 148 CVCExplorer.dumpCertificate(source.cvc); 149 break; 150 case CVCExplorer.REMOVESTR: 151 source.remove(); 152 break; 153 } 154 } 155 156 157 158 /** 159 * Creates the top level node and displays the outline 160 */ 161 CVCExplorer.prototype.run = function() { 162 this.node = new OutlineNode("CVCExplorer"); 163 this.node.setToolTip("Right click to select file"); 164 this.node.setUserObject(this); 165 this.node.setContextMenu([CVCExplorer.FILESTR]); 166 this.node.show(); 167 print("Click with the right mouse button on the \"CVCExplorer\" entry to select a file"); 168 } 169 170 171 172 var instance = new CVCExplorer(); 173 instance.run(); 174