src/share/classes/sun/security/pkcs11/wrapper/PKCS11.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 
   5 /* Copyright  (c) 2002 Graz University of Technology. All rights reserved.
   6  *
   7  * Redistribution and use in  source and binary forms, with or without
   8  * modification, are permitted  provided that the following conditions are met:
   9  *
  10  * 1. Redistributions of  source code must retain the above copyright notice,
  11  *    this list of conditions and the following disclaimer.
  12  *
  13  * 2. Redistributions in  binary form must reproduce the above copyright notice,
  14  *    this list of conditions and the following disclaimer in the documentation
  15  *    and/or other materials provided with the distribution.
  16  *
  17  * 3. The end-user documentation included with the redistribution, if any, must
  18  *    include the following acknowledgment:
  19  *
  20  *    "This product includes software developed by IAIK of Graz University of
  21  *     Technology."
  22  *


  38  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  39  *  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  40  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  41  *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  42  *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  43  *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  44  *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  45  *  POSSIBILITY  OF SUCH DAMAGE.
  46  */
  47 
  48 package sun.security.pkcs11.wrapper;
  49 
  50 import java.io.File;
  51 import java.io.IOException;
  52 import java.util.*;
  53 
  54 import java.security.AccessController;
  55 import java.security.PrivilegedAction;
  56 
  57 import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
  58 import javax.tools.annotation.GenerateNativeHeader;
  59 
  60 /**
  61  * This is the default implementation of the PKCS11 interface. IT connects to
  62  * the pkcs11wrapper.dll file, which is the native part of this library.
  63  * The strange and awkward looking initialization was chosen to avoid calling
  64  * loadLibrary from a static initialization block, because this would complicate
  65  * the use in applets.
  66  *
  67  * @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at>
  68  * @author Martin Schlaeffer <schlaeff@sbox.tugraz.at>
  69  * @invariants (pkcs11ModulePath_ <> null)
  70  */
  71 /* No native methods here, but the constants are needed in the supporting JNI code */
  72 @GenerateNativeHeader
  73 public class PKCS11 {
  74 
  75     /**
  76      * The name of the native part of the wrapper; i.e. the filename without
  77      * the extension (e.g. ".DLL" or ".so").
  78      */
  79     private static final String PKCS11_WRAPPER = "j2pkcs11";
  80 
  81     static {
  82         // cannot use LoadLibraryAction because that would make the native
  83         // library available to the bootclassloader, but we run in the
  84         // extension classloader.
  85         AccessController.doPrivileged(new PrivilegedAction<Object>() {
  86             public Object run() {
  87                 System.loadLibrary(PKCS11_WRAPPER);
  88                 return null;
  89             }
  90         });
  91         initializeLibrary();
  92     }


   1 /*
   2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 
   5 /* Copyright  (c) 2002 Graz University of Technology. All rights reserved.
   6  *
   7  * Redistribution and use in  source and binary forms, with or without
   8  * modification, are permitted  provided that the following conditions are met:
   9  *
  10  * 1. Redistributions of  source code must retain the above copyright notice,
  11  *    this list of conditions and the following disclaimer.
  12  *
  13  * 2. Redistributions in  binary form must reproduce the above copyright notice,
  14  *    this list of conditions and the following disclaimer in the documentation
  15  *    and/or other materials provided with the distribution.
  16  *
  17  * 3. The end-user documentation included with the redistribution, if any, must
  18  *    include the following acknowledgment:
  19  *
  20  *    "This product includes software developed by IAIK of Graz University of
  21  *     Technology."
  22  *


  38  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  39  *  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  40  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  41  *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  42  *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  43  *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  44  *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  45  *  POSSIBILITY  OF SUCH DAMAGE.
  46  */
  47 
  48 package sun.security.pkcs11.wrapper;
  49 
  50 import java.io.File;
  51 import java.io.IOException;
  52 import java.util.*;
  53 
  54 import java.security.AccessController;
  55 import java.security.PrivilegedAction;
  56 
  57 import static sun.security.pkcs11.wrapper.PKCS11Constants.*;

  58 
  59 /**
  60  * This is the default implementation of the PKCS11 interface. IT connects to
  61  * the pkcs11wrapper.dll file, which is the native part of this library.
  62  * The strange and awkward looking initialization was chosen to avoid calling
  63  * loadLibrary from a static initialization block, because this would complicate
  64  * the use in applets.
  65  *
  66  * @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at>
  67  * @author Martin Schlaeffer <schlaeff@sbox.tugraz.at>
  68  * @invariants (pkcs11ModulePath_ <> null)
  69  */


  70 public class PKCS11 {
  71 
  72     /**
  73      * The name of the native part of the wrapper; i.e. the filename without
  74      * the extension (e.g. ".DLL" or ".so").
  75      */
  76     private static final String PKCS11_WRAPPER = "j2pkcs11";
  77 
  78     static {
  79         // cannot use LoadLibraryAction because that would make the native
  80         // library available to the bootclassloader, but we run in the
  81         // extension classloader.
  82         AccessController.doPrivileged(new PrivilegedAction<Object>() {
  83             public Object run() {
  84                 System.loadLibrary(PKCS11_WRAPPER);
  85                 return null;
  86             }
  87         });
  88         initializeLibrary();
  89     }