    001    /* Copyright  (c) 2002 Graz University of Technology. All rights reserved.
    002     *
    003     * Redistribution and use in  source and binary forms, with or without
    004     * modification, are permitted  provided that the following conditions are met:
    005     *
    006     * 1. Redistributions of  source code must retain the above copyright notice,
    007     *    this list of conditions and the following disclaimer.
    008     *
    009     * 2. Redistributions in  binary form must reproduce the above copyright notice,
    010     *    this list of conditions and the following disclaimer in the documentation
    011     *    and/or other materials provided with the distribution.
    012     *
    013     * 3. The end-user documentation included with the redistribution, if any, must
    014     *    include the following acknowledgment:
    015     *
    016     *    "This product includes software developed by IAIK of Graz University of
    017     *     Technology."
    018     *
    019     *    Alternately, this acknowledgment may appear in the software itself, if
    020     *    and wherever such third-party acknowledgments normally appear.
    021     *
    022     * 4. The names "Graz University of Technology" and "IAIK of Graz University of
    023     *    Technology" must not be used to endorse or promote products derived from
    024     *    this software without prior written permission.
    025     *
    026     * 5. Products derived from this software may not be called
    027     *    "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior
    028     *    written permission of Graz University of Technology.
    029     *
    030     *  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
    031     *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    032     *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    033     *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE
    034     *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
    035     *  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    036     *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
    037     *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
    038     *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    039     *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    040     *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    041     *  POSSIBILITY  OF SUCH DAMAGE.
    042     */
    043
    044    package demo.pkcs.pkcs11;
    045
    046    import java.io.PrintWriter;
    047
    048    import iaik.pkcs.pkcs11.DefaultInitializeArgs;
    049    import iaik.pkcs.pkcs11.DefaultMutexHandler;
    050    import iaik.pkcs.pkcs11.Info;
    051    import iaik.pkcs.pkcs11.InitializeArgs;
    052    import iaik.pkcs.pkcs11.Module;
    053
    054
    055
    056    /**
    057     * This demo program tries to call initialize with some arguments.
    058     *
    059     * @author <a href="mailto:Karl.Scheibelhofer@iaik.at"> Karl Scheibelhofer </a>
    060     * @version 0.1
    061     * @invariants
    062     */
    063    public class DefaultInitArgs {
    064
    065      static PrintWriter output_;
    066
    067      static {
    068        try {
    069          //output_ = new PrintWriter(new FileWriter("GetInfo_output.txt"), true);
    070          output_ = new PrintWriter(System.out, true);
    071        } catch (Throwable thr) {
    072          thr.printStackTrace();
    073          output_ = new PrintWriter(System.out, true);
    074        }
    075      }
    076
    077      public static void main(String[] args) {
    078        if ((args.length == 1) || (args.length == 2)){
    079          try {
    080            output_.println("################################################################################");
    081            output_.println("load and initialize module \"" + args[0] + "\" using default InitializeArgs");
    082            output_.flush();
    083            Module pkcs11Module = Module.getInstance(args[0]);
    084            InitializeArgs initArgs = new DefaultInitializeArgs(new DefaultMutexHandler(), false, true);
    085            pkcs11Module.initialize(initArgs);
    086
    087            Info info = pkcs11Module.getInfo();
    088            output_.println(info);
    089            output_.println("################################################################################");
    090          } catch (Throwable ex) {
    091            ex.printStackTrace();
    092          }
    093        } else {
    094          printUsage();
    095        }
    096        System.gc(); // to finalize and disconnect the pkcs11Module
    097      }
    098
    099      protected static void printUsage() {
    100        output_.println("DefaultInitArgs <PKCS#11 module name>");
    101        output_.println("e.g.: DefaultInitArgs slbck.dll");
    102      }
    103
    104    }