The PKCS#11 provider of the OpenSC project. This provider is based on the RSA Security Inc. PKCS#11 Cryptographic Token Interface (Cryptoki) . @author wglas
| 53 | * @author wglas |
| 54 | */ |
| 55 | public class PKCS11Provider extends Provider implements DestroyableParent |
| 56 | { |
| 57 | static private final Log log = LogFactory.getLog(PKCS11Provider.class); |
| 58 | |
| 59 | /** |
| 60 | * To be changed, when the interface changes. |
| 61 | */ |
| 62 | private static final long serialVersionUID = -2568219416560640437L; |
| 63 | |
| 64 | /* This value has to correspond to the value of version in build.xml */ |
| 65 | private static final double version = 0.2; |
| 66 | /* This value has to correspond to the value of patchlevel in build.xml */ |
| 67 | private static final double patchlevel = 0; |
| 68 | |
| 69 | static { |
| 70 | System.loadLibrary("opensc-PKCS11-"+version); |
| 71 | } |
| 72 | |
| 73 | private long pkcs11ModuleHandle; |
| 74 | private ShutdownThread shutdownThread; |
| 75 | private DestroyableHolder destroyableHolder; |
| 76 | |
| 77 | private native long loadNativePKCS11Module(String filename) throws PKCS11Exception; |
| 78 | private native void unloadPKCS11Module(long handle) throws PKCS11Exception; |
| 79 | |
| 80 | /* (non-Javadoc) |
| 81 | * @see java.lang.Object#finalize() |
| 82 | */ |
| 83 | @Override |
| 84 | protected void finalize() throws Throwable |
| 85 | { |
| 86 | cleanup(); |
| 87 | super.finalize(); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Additional function, which may e used by application to cleanup all |
| 92 | * allocated C resources of the underlying JNI plugin. |
| 93 | */ |
| 94 | public synchronized void cleanup() |
| 95 | { |
| 96 | if (this.pkcs11ModuleHandle != 0L) |
| 97 | { |
| 98 | try |
| 99 | { |
| 100 | this.destroyableHolder.destroy(); |
| 101 | } catch (DestroyFailedException e) |
| 102 | { |
| 103 | log.error("Failure during destruction of C resources:",e); |
| 104 | } |
| 105 | |
| 106 | try |
| 107 | { |
| 108 | unloadPKCS11Module(this.pkcs11ModuleHandle); |
| 109 | } catch (PKCS11Exception e) |
| 110 | { |
| 111 | log.error("Failure unloading PKCS#11 module:",e); |
| 112 | } |
nothing calls this directly
no outgoing calls
no test coverage detected