    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.applet.Applet;
    047
    048    import iaik.pkcs.pkcs11.Module;
    049    import iaik.pkcs.pkcs11.Info;
    050
    051
    052
    053    /**
    054     * This demo program lists information about a module.
    055     *
    056     * @author <a href="mailto:Karl.Scheibelhofer@iaik.at"> Karl Scheibelhofer </a>
    057     * @version 0.1
    058     * @invariants
    059     */
    060    public class ModuleInfo extends Applet {
    061
    062      protected Module pkcs11Module_;
    063
    064      /**
    065       * Initialize this applet. Loads and initializes the module.
    066       */
    067      public void init() {
    068        String moduleName = getParameter("ModuleName");
    069        System.out.println("initializing module " + moduleName+ " ... ");
    070        try {
    071          pkcs11Module_ = Module.getInstance(moduleName);
    072          pkcs11Module_.initialize(null);
    073        } catch (Throwable ex) {
    074          ex.printStackTrace();
    075        }
    076        System.out.println("...finished initializing");
    077      }
    078
    079      /**
    080       * Start this applet. Gets info about the module and dumps it to the console.
    081       */
    082      public void start() {
    083        System.out.println("starting... ");
    084
    085        try {
    086          System.out.print("getting module info...");
    087          Info info = pkcs11Module_.getInfo();
    088          System.out.println("finished");
    089          System.out.println("module info is:");
    090          System.out.println(info);
    091        } catch (Throwable ex) {
    092          ex.printStackTrace();
    093        }
    094        System.out.flush();
    095        System.err.flush();
    096
    097        System.out.println("...finished starting");
    098      }
    099
    100      /**
    101       * Stop this applet. Does effectively nothing.
    102       */
    103      public void stop() {
    104        System.out.print("stopping... ");
    105        System.out.println("finished");
    106      }
    107
    108      /**
    109       * Destroy this applet. Finalizes the module.
    110       */
    111      public void destroy() {
    112        System.out.print("preparing for unloading...");
    113        try {
    114          pkcs11Module_.finalize(null);
    115          pkcs11Module_ = null;
    116        } catch (Throwable ex) {
    117          ex.printStackTrace();
    118        }
    119        System.out.println("finished");
    120     }
    121
    122    }