[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r3646 - trunk/softHSM/src/bin

Rickard Bellgrim rickard.bellgrim at iis.se
Thu Aug 5 13:51:43 CEST 2010


Author: rb
Date: 2010-08-05 13:51:43 +0200 (Thu, 05 Aug 2010)
New Revision: 3646

Modified:
   trunk/softHSM/src/bin/softhsm.cpp
   trunk/softHSM/src/bin/softhsm.h
Log:
We need to initialize Botan if we are using a PKCS#11 library which does not use Botan.


Modified: trunk/softHSM/src/bin/softhsm.cpp
===================================================================
--- trunk/softHSM/src/bin/softhsm.cpp	2010-08-05 11:21:50 UTC (rev 3645)
+++ trunk/softHSM/src/bin/softhsm.cpp	2010-08-05 11:51:43 UTC (rev 3646)
@@ -157,6 +157,7 @@
 
   moduleHandle = NULL;
   p11 = NULL;
+  bool was_initialized = false;
 
   while ((opt = getopt_long(argc, argv, "hv", long_options, &option_index)) != -1) {
     switch (opt) {
@@ -219,6 +220,7 @@
   // No action given, display the usage.
   if(action == 0) {
     usage();
+    return 0;
   } else {
     CK_C_GetFunctionList pGetFunctionList = loadLibrary(module);
     if(pGetFunctionList == NULL) {
@@ -234,6 +236,20 @@
     }
   }
 
+  // The PKCS#11 library might be using Botan
+  // Check if it has already initialized Botan
+  Library_State* state = swap_global_state(0);
+  // now put it back
+  swap_global_state(state);
+
+  if(state) {
+    was_initialized = true;
+  }
+
+  if(was_initialized == false) {
+    LibraryInitializer::initialize("thread_safe=true");
+  }
+
   // We should create the token.
   if(doInitToken) {
     initToken(slot, label, soPIN, userPIN);
@@ -258,6 +274,10 @@
     }
   }
 
+  if(was_initialized == false) {
+    LibraryInitializer::deinitialize();
+  }
+
   if(action) {
     p11->C_Finalize(NULL_PTR);
     if(moduleHandle) {

Modified: trunk/softHSM/src/bin/softhsm.h
===================================================================
--- trunk/softHSM/src/bin/softhsm.h	2010-08-05 11:21:50 UTC (rev 3645)
+++ trunk/softHSM/src/bin/softhsm.h	2010-08-05 11:51:43 UTC (rev 3646)
@@ -39,6 +39,7 @@
 #include <botan/pkcs8.h>
 #include <botan/bigint.h>
 #include <botan/if_algo.h>
+#include <botan/init.h>
 using namespace Botan;
 
 typedef struct key_material_t {




More information about the Opendnssec-commits mailing list