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