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/ExplicitSignedDataStreamDemo.java 15    12.02.25 17:58 Dbratko $
029// $Revision: 15 $
030//
031
032package demo.cms.pkcs11;
033
034// class and interface imports
035import demo.DemoUtil;
036
037
038/**
039 * This class shows how to sign data (explicit, the content data is included) 
040 * according to CMS using the IAIK PKCS#11 provider for accessing the private key
041 * on a smart card. This implementation uses the <code>SecurityProvider</code> 
042 * feature of the IAIK-CMS toolkit.
043 * <p>
044 * For running this demo the following packages  are required (in addition to 
045 * <code>iaik_cms.jar</code> and <code>iaik_cms_demo.jar</code>):
046 * <ul>
047 *    <li>
048 *       <code>iaik_jce(full).jar</code> (IAIK-JCE crypto toolkit)
049 *    </li>   
050 *    <li>
051 *       <code>iaikPkcs11Wrapper.jar</code> (IAIK PKCS#11 Wrapper)
052 *    </li>
053 *    <li>
054 *       <code>iaikPkcs11Provider.jar</code> (IAIK PKCS#11 Provider)
055 *    </li>
056 *    <li>
057 *       The shared PKCS#11 library (<code>pkcs11wrapper.dll</code> for Windows
058 *       and <code>libpkcs11wrapper.so</code> for Unix)
059 *     </li>  
060 * </ul>
061 * <code>iaik_cms.jar</code>, <code>iaik_cms_demo.jar</code>, <code>iaik_jce(full).jar</code>,
062 * <code>iaikPkcs11Wrapper.jar</code> and <code>iaikPkcs11Provider.jar</code> have to
063 * be put into the classpath, the shared library (<code>pkcs11wrapper.dll</code> or
064 * <code>libpkcs11wrapper.so</code>) has to be in your system library search path
065 * or in your VM library path, e.g. (on Windows, assuming that all jar files are 
066 * located in a lib sub-directory and the dll is in a lib/win64 sub-directory):
067 * <pre>
068 * java -Djava.library.path=lib/win64 
069 *      -cp lib/iaik_jce.jar;lib/iaikPkcs11Wrapper.jar;lib/iaikPkcs11Provider.jar;lib/iaik_cms.jar;lib/iaik_cms_demo.jar
070 *      demo.pkcs11.ImplicitSignedDataStreamDemo &lt;pkcs11Module&gt;.dll
071 * </pre>
072 */
073public class ExplicitSignedDataStreamDemo extends SignedDataStreamDemo {
074  
075  /**
076   * Creates a ExplicitSignedDataStreamDemo object that has to be explicitly 
077   * {@link PKCS11Demo#init(String, char[]) initialized} with a module name.
078   */
079  public ExplicitSignedDataStreamDemo() {
080    // install provider in super class    
081    super();
082    System.out.println();
083    System.out.println("********************************************************************************************************");
084    System.out.println("*                               PKCS#11  ExplicitSignedDataStreamDemo                                  *");
085    System.out.println("* (shows the usage of the CMS SignedData type implementation (explicit) with the IAIK-PKCS11 provider) *");
086    System.out.println("********************************************************************************************************");
087    System.out.println();
088  }
089  
090  /**
091   * Creates a ExplicitSignedDataStreamDemo object for the given module name.
092   * 
093   * @param moduleName the name of the module
094   * @param userPin the user-pin (password) for the TokenKeyStore
095   *                (may be <code>null</code> to pop-up a dialog asking for the pin)
096   */
097  public ExplicitSignedDataStreamDemo(String moduleName, char[] userPin) {
098    // install provider in super class 
099    this();
100    init(moduleName, userPin);
101
102  }
103
104
105  
106  /**
107   * This is the main method that is called by the JVM during startup.
108   *
109   * @param args These are the command line arguments.
110   */
111  public static void main(String[] args) {
112    
113    SignedDataStreamDemo demo = new ExplicitSignedDataStreamDemo();
114    demo.init(args); 
115    demo.start(false);
116    DemoUtil.waitKey();
117  }
118  
119 
120}