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