summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-02-06 21:57:45 +0100
committerStef Walter <stefw@gnome.org>2013-05-21 10:47:51 +0200
commit5c19f0cf66495f00ccf69eba1d0915f862a88c8d (patch)
treee8ae733062507a0a4cc5c134d1fdd62cf055cddd /tools
parentff853bd7902e271256cada4a1b20a3d46b519b69 (diff)
p11-kit: Managed PKCS#11 module loading
Support a new managed style module loading for PKCS#11 modules. This allows us to better coordinate between multiple callers of the same PKCS#11 modules and provide hooks into their behavior. This meant redoing the public facing API. The old methods are now deprecated, marked and documented as such.
Diffstat (limited to 'tools')
-rw-r--r--tools/extract.c15
-rw-r--r--tools/list.c16
-rw-r--r--tools/tests/test-extract.c7
-rw-r--r--tools/tests/test-openssl.c9
-rw-r--r--tools/tests/test-pem.c9
-rw-r--r--tools/tests/test-x509.c9
6 files changed, 31 insertions, 34 deletions
diff --git a/tools/extract.c b/tools/extract.c
index cd0f369..3d1fee7 100644
--- a/tools/extract.c
+++ b/tools/extract.c
@@ -231,7 +231,7 @@ limit_modules_if_necessary (CK_FUNCTION_LIST_PTR *modules,
/* TODO: This logic will move once we merge our p11-kit managed code */
for (i = 0, out = 0; modules[i] != NULL; i++) {
- string = p11_kit_registered_option (modules[i], "trust-policy");
+ string = p11_kit_config_option (modules[i], "trust-policy");
if (string && strcmp (string, "yes") == 0)
modules[out++] = modules[i];
else if (string && strcmp (string, "no") != 0)
@@ -305,7 +305,6 @@ p11_tool_extract (int argc,
CK_ATTRIBUTE *match;
P11KitUri *uri;
int opt = 0;
- CK_RV rv;
int ret;
enum {
@@ -435,13 +434,10 @@ p11_tool_extract (int argc,
if (uri && p11_kit_uri_any_unrecognized (uri))
p11_message ("uri contained unrecognized components, nothing will be extracted");
- rv = p11_kit_initialize_registered ();
- if (rv != CKR_OK) {
- p11_message ("couldn't initialize registered modules: %s", p11_kit_strerror (rv));
+ modules = p11_kit_modules_load_and_initialize (0);
+ if (!modules)
return 1;
- }
- modules = p11_kit_registered_modules ();
limit_modules_if_necessary (modules, ex.flags);
iter = p11_kit_iter_new (uri);
@@ -456,8 +452,9 @@ p11_tool_extract (int argc,
p11_extract_info_cleanup (&ex);
p11_kit_iter_free (iter);
p11_kit_uri_free (uri);
- free (modules);
- p11_kit_finalize_registered ();
+ p11_kit_modules_finalize (modules);
+ p11_kit_modules_release (modules);
+
return ret;
}
diff --git a/tools/list.c b/tools/list.c
index da99940..fe028ae 100644
--- a/tools/list.c
+++ b/tools/list.c
@@ -203,20 +203,15 @@ print_modules (void)
CK_FUNCTION_LIST_PTR *module_list;
char *name;
char *path;
- CK_RV rv;
int i;
- rv = p11_kit_initialize_registered ();
- if (rv != CKR_OK) {
- p11_message ("couldn't initialize registered modules: %s",
- p11_kit_strerror (rv));
+ module_list = p11_kit_modules_load_and_initialize (0);
+ if (!module_list)
return 1;
- }
- module_list = p11_kit_registered_modules ();
for (i = 0; module_list[i]; i++) {
- name = p11_kit_registered_module_to_name (module_list[i]);
- path = p11_kit_registered_option (module_list[i], "module");
+ name = p11_kit_module_get_name (module_list[i]);
+ path = p11_kit_config_option (module_list[i], "module");
printf ("%s: %s\n",
name ? name : "(null)",
@@ -226,9 +221,8 @@ print_modules (void)
free (name);
free (path);
}
- free (module_list);
- p11_kit_finalize_registered ();
+ p11_kit_modules_finalize_and_release (module_list);
return 0;
}
diff --git a/tools/tests/test-extract.c b/tools/tests/test-extract.c
index 74e3c9c..a3db8d8 100644
--- a/tools/tests/test-extract.c
+++ b/tools/tests/test-extract.c
@@ -32,6 +32,8 @@
* Author: Stef Walter <stefw@collabora.co.uk>
*/
+#define P11_KIT_DISABLE_DEPRECATED
+
#include "config.h"
#include "CuTest.h"
@@ -145,9 +147,10 @@ setup (CuTest *tc)
{
CK_RV rv;
+ mock_module_reset ();
memcpy (&test.module, &mock_module, sizeof (CK_FUNCTION_LIST));
- rv = p11_kit_initialize_module (&test.module);
+ rv = test.module.C_Initialize (NULL);
CuAssertIntEquals (tc, CKR_OK, rv);
test.iter = p11_kit_iter_new (NULL);
@@ -164,7 +167,7 @@ teardown (CuTest *tc)
p11_kit_iter_free (test.iter);
- rv = p11_kit_finalize_module (&test.module);
+ rv = test.module.C_Finalize (NULL);
CuAssertIntEquals (tc, CKR_OK, rv);
}
diff --git a/tools/tests/test-openssl.c b/tools/tests/test-openssl.c
index 215e0da..c778aa7 100644
--- a/tools/tests/test-openssl.c
+++ b/tools/tests/test-openssl.c
@@ -32,6 +32,8 @@
* Author: Stef Walter <stefw@collabora.co.uk>
*/
+#define P11_KIT_DISABLE_DEPRECATED
+
#include "config.h"
#include "CuTest.h"
@@ -69,12 +71,11 @@ setup (CuTest *tc)
{
CK_RV rv;
+ mock_module_reset ();
memcpy (&test.module, &mock_module, sizeof (CK_FUNCTION_LIST));
- rv = p11_kit_initialize_module (&test.module);
+ rv = test.module.C_Initialize (NULL);
CuAssertIntEquals (tc, CKR_OK, rv);
- mock_module_reset_objects (MOCK_SLOT_ONE_ID);
-
test.iter = p11_kit_iter_new (NULL);
p11_extract_info_init (&test.ex);
@@ -96,7 +97,7 @@ teardown (CuTest *tc)
p11_extract_info_cleanup (&test.ex);
p11_kit_iter_free (test.iter);
- rv = p11_kit_finalize_module (&test.module);
+ rv = test.module.C_Finalize (NULL);
CuAssertIntEquals (tc, CKR_OK, rv);
}
diff --git a/tools/tests/test-pem.c b/tools/tests/test-pem.c
index dc1cb08..4024bac 100644
--- a/tools/tests/test-pem.c
+++ b/tools/tests/test-pem.c
@@ -32,6 +32,8 @@
* Author: Stef Walter <stefw@collabora.co.uk>
*/
+#define P11_KIT_DISABLE_DEPRECATED
+
#include "config.h"
#include "CuTest.h"
@@ -66,12 +68,11 @@ setup (CuTest *tc)
{
CK_RV rv;
+ mock_module_reset ();
memcpy (&test.module, &mock_module, sizeof (CK_FUNCTION_LIST));
- rv = p11_kit_initialize_module (&test.module);
+ rv = test.module.C_Initialize (NULL);
CuAssertIntEquals (tc, CKR_OK, rv);
- mock_module_reset_objects (MOCK_SLOT_ONE_ID);
-
test.iter = p11_kit_iter_new (NULL);
p11_extract_info_init (&test.ex);
@@ -93,7 +94,7 @@ teardown (CuTest *tc)
p11_extract_info_cleanup (&test.ex);
p11_kit_iter_free (test.iter);
- rv = p11_kit_finalize_module (&test.module);
+ rv = test.module.C_Finalize (NULL);
CuAssertIntEquals (tc, CKR_OK, rv);
}
diff --git a/tools/tests/test-x509.c b/tools/tests/test-x509.c
index e952e53..5093743 100644
--- a/tools/tests/test-x509.c
+++ b/tools/tests/test-x509.c
@@ -32,6 +32,8 @@
* Author: Stef Walter <stefw@collabora.co.uk>
*/
+#define P11_KIT_DISABLE_DEPRECATED
+
#include "config.h"
#include "CuTest.h"
@@ -66,12 +68,11 @@ setup (CuTest *tc)
{
CK_RV rv;
+ mock_module_reset ();
memcpy (&test.module, &mock_module, sizeof (CK_FUNCTION_LIST));
- rv = p11_kit_initialize_module (&test.module);
+ rv = test.module.C_Initialize (NULL);
CuAssertIntEquals (tc, CKR_OK, rv);
- mock_module_reset_objects (MOCK_SLOT_ONE_ID);
-
test.iter = p11_kit_iter_new (NULL);
p11_extract_info_init (&test.ex);
@@ -93,7 +94,7 @@ teardown (CuTest *tc)
p11_extract_info_cleanup (&test.ex);
p11_kit_iter_free (test.iter);
- rv = p11_kit_finalize_module (&test.module);
+ rv = test.module.C_Finalize (NULL);
CuAssertIntEquals (tc, CKR_OK, rv);
}