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/ImplicitSignedDataStreamDemo.java 16 12.02.25 17:58 Dbratko $
059 // $Revision: 16 $
060 //
061
062 package demo.cms.pkcs11;
063
064 import demo.DemoUtil;
065
066 /**
067 * This class shows how to sign data (implicit, the content data is included)
068 * according to CMS using the IAIK PKCS#11 provider for accessing the private key
069 * on a smart card. This implementation uses the <code>SecurityProvider</code>
070 * feature of the IAIK-CMS toolkit.
071 * <p>
072 * For running this demo the following packages are required (in addition to
073 * <code>iaik_cms.jar</code> and <code>iaik_cms_demo.jar</code>):
074 * <ul>
075 * <li>
076 * <code>iaik_jce(full).jar</code> (IAIK-JCE crypto toolkit)
077 * </li>
078 * <li>
079 * <code>iaikPkcs11Wrapper.jar</code> (IAIK PKCS#11 Wrapper)
080 * </li>
081 * <li>
082 * <code>iaikPkcs11Provider.jar</code> (IAIK PKCS#11 Provider)
083 * </li>
084 * <li>
085 * The shared PKCS#11 library (<code>pkcs11wrapper.dll</code> for Windows
086 * and <code>libpkcs11wrapper.so</code> for Unix)
087 * </li>
088 * </ul>
089 * <code>iaik_cms.jar</code>, <code>iaik_cms_demo.jar</code>, <code>iaik_jce(full).jar</code>,
090 * <code>iaikPkcs11Wrapper.jar</code> and <code>iaikPkcs11Provider.jar</code> have to
091 * be put into the classpath, the shared library (<code>pkcs11wrapper.dll</code> or
092 * <code>libpkcs11wrapper.so</code>) has to be in your system library search path
093 * or in your VM library path, e.g. (on Windows, assuming that all jar files are
094 * located in a lib sub-directory and the dll is in a lib/win64 sub-directory):
095 * <pre>
096 * java -Djava.library.path=lib/win64
097 * -cp lib/iaik_jce.jar;lib/iaikPkcs11Wrapper.jar;lib/iaikPkcs11Provider.jar;lib/iaik_cms.jar;lib/iaik_cms_demo.jar
098 * demo.pkcs11.ImplicitSignedDataStreamDemo <pkcs11Module>.dll
099 * </pre>
100 */
101 public class ImplicitSignedDataStreamDemo extends SignedDataStreamDemo {
102
103 /**
104 * Creates a ImplicitSignedDataStreamDemo object that has to be explicitly
105 * {@link PKCS11Demo#init(String, char[]) initialized} with a module name.
106 */
107 public ImplicitSignedDataStreamDemo() {
108 // install provider in super class
109 super();
110 System.out.println();
111 System.out.println("********************************************************************************************************");
112 System.out.println("* PKCS#11 ImplicitSignedDataStreamDemo *");
113 System.out.println("* (shows the usage of the CMS SignedData type implementation (implicit) with the IAIK-PKCS11 provider) *");
114 System.out.println("********************************************************************************************************");
115 System.out.println();
116 }
117
118 /**
119 * Creates a ImplicitSignedDataStreamDemo object for the given module name.
120 *
121 * @param moduleName the name of the module
122 * @param userPin the user-pin (password) for the TokenKeyStore
123 * (may be <code>null</code> to pop-up a dialog asking for the pin)
124 */
125 public ImplicitSignedDataStreamDemo(String moduleName, char[] userPin) {
126 // install provider in super class
127 this();
128 init(moduleName, userPin);
129
130 }
131
132 /**
133 * This is the main method that is called by the JVM during startup.
134 *
135 * @param args These are the command line arguments.
136 */
137 public static void main(String[] args) {
138
139 SignedDataStreamDemo demo = new ImplicitSignedDataStreamDemo();
140 demo.init(args);
141 demo.start(true);
142 DemoUtil.waitKey();
143 }
144
145 }