001 // Copyright (C) 2002 IAIK 002 // https://jce.iaik.tugraz.at 003 // 004 // Copyright (C) 2003 - 2025 Stiftung Secure Information and 005 // Communication Technologies SIC 006 // https://sic.tech 007 // 008 // All rights reserved. 009 // 010 // Redistribution and use in source and binary forms, with or without 011 // modification, are permitted provided that the following conditions 012 // are met: 013 // 1. Redistributions of source code must retain the above copyright 014 // notice, this list of conditions and the following disclaimer. 015 // 2. Redistributions in binary form must reproduce the above copyright 016 // notice, this list of conditions and the following disclaimer in the 017 // documentation and/or other materials provided with the distribution. 018 // 019 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 020 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 021 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 022 // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 023 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 024 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 025 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 026 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 027 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 028 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 029 // SUCH DAMAGE. 030 031 // Copyright (C) 2002 IAIK 032 // https://sic.tech/ 033 // 034 // Copyright (C) 2003 - 2025 Stiftung Secure Information and 035 // Communication Technologies SIC 036 // https://sic.tech/ 037 // 038 // All rights reserved. 039 // 040 // This source is provided for inspection purposes and recompilation only, 041 // unless specified differently in a contract with IAIK. This source has to 042 // be kept in strict confidence and must not be disclosed to any third party 043 // under any circumstances. Redistribution in source and binary forms, with 044 // or without modification, are <not> permitted in any case! 045 // 046 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 047 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 048 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 049 // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 050 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 051 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 052 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 053 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 054 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 055 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 056 // SUCH DAMAGE. 057 // 058 // $Header: /IAIK-CMS/current/src/demo/cms/pkcs11/ExplicitSignedDataStreamDemo.java 15 12.02.25 17:58 Dbratko $ 059 // $Revision: 15 $ 060 // 061 062 package demo.cms.pkcs11; 063 064 // class and interface imports 065 import demo.DemoUtil; 066 067 068 /** 069 * This class shows how to sign data (explicit, the content data is included) 070 * according to CMS using the IAIK PKCS#11 provider for accessing the private key 071 * on a smart card. This implementation uses the <code>SecurityProvider</code> 072 * feature of the IAIK-CMS toolkit. 073 * <p> 074 * For running this demo the following packages are required (in addition to 075 * <code>iaik_cms.jar</code> and <code>iaik_cms_demo.jar</code>): 076 * <ul> 077 * <li> 078 * <code>iaik_jce(full).jar</code> (IAIK-JCE crypto toolkit) 079 * </li> 080 * <li> 081 * <code>iaikPkcs11Wrapper.jar</code> (IAIK PKCS#11 Wrapper) 082 * </li> 083 * <li> 084 * <code>iaikPkcs11Provider.jar</code> (IAIK PKCS#11 Provider) 085 * </li> 086 * <li> 087 * The shared PKCS#11 library (<code>pkcs11wrapper.dll</code> for Windows 088 * and <code>libpkcs11wrapper.so</code> for Unix) 089 * </li> 090 * </ul> 091 * <code>iaik_cms.jar</code>, <code>iaik_cms_demo.jar</code>, <code>iaik_jce(full).jar</code>, 092 * <code>iaikPkcs11Wrapper.jar</code> and <code>iaikPkcs11Provider.jar</code> have to 093 * be put into the classpath, the shared library (<code>pkcs11wrapper.dll</code> or 094 * <code>libpkcs11wrapper.so</code>) has to be in your system library search path 095 * or in your VM library path, e.g. (on Windows, assuming that all jar files are 096 * located in a lib sub-directory and the dll is in a lib/win64 sub-directory): 097 * <pre> 098 * java -Djava.library.path=lib/win64 099 * -cp lib/iaik_jce.jar;lib/iaikPkcs11Wrapper.jar;lib/iaikPkcs11Provider.jar;lib/iaik_cms.jar;lib/iaik_cms_demo.jar 100 * demo.pkcs11.ImplicitSignedDataStreamDemo <pkcs11Module>.dll 101 * </pre> 102 */ 103 public class ExplicitSignedDataStreamDemo extends SignedDataStreamDemo { 104 105 /** 106 * Creates a ExplicitSignedDataStreamDemo object that has to be explicitly 107 * {@link PKCS11Demo#init(String, char[]) initialized} with a module name. 108 */ 109 public ExplicitSignedDataStreamDemo() { 110 // install provider in super class 111 super(); 112 System.out.println(); 113 System.out.println("********************************************************************************************************"); 114 System.out.println("* PKCS#11 ExplicitSignedDataStreamDemo *"); 115 System.out.println("* (shows the usage of the CMS SignedData type implementation (explicit) with the IAIK-PKCS11 provider) *"); 116 System.out.println("********************************************************************************************************"); 117 System.out.println(); 118 } 119 120 /** 121 * Creates a ExplicitSignedDataStreamDemo object for the given module name. 122 * 123 * @param moduleName the name of the module 124 * @param userPin the user-pin (password) for the TokenKeyStore 125 * (may be <code>null</code> to pop-up a dialog asking for the pin) 126 */ 127 public ExplicitSignedDataStreamDemo(String moduleName, char[] userPin) { 128 // install provider in super class 129 this(); 130 init(moduleName, userPin); 131 132 } 133 134 135 136 /** 137 * This is the main method that is called by the JVM during startup. 138 * 139 * @param args These are the command line arguments. 140 */ 141 public static void main(String[] args) { 142 143 SignedDataStreamDemo demo = new ExplicitSignedDataStreamDemo(); 144 demo.init(args); 145 demo.start(false); 146 DemoUtil.waitKey(); 147 } 148 149 150 }