summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2015-07-10 12:11:49 +0200
committerSumit Bose <sbose@redhat.com>2015-07-17 19:22:14 +0200
commit9c1c626080093b5ee93e6f801ae44139cf0ad097 (patch)
tree03bf5102b0ebeae9daafd14579f08d7dacbf4b34 /src
parentf6d366ebd1307dfd36a907e55f32a66caf2b0f9d (diff)
downloadsssd-9c1c626080093b5ee93e6f801ae44139cf0ad097.tar.gz
sssd-9c1c626080093b5ee93e6f801ae44139cf0ad097.tar.xz
sssd-9c1c626080093b5ee93e6f801ae44139cf0ad097.zip
WIP: p11-kit version of p11_child
Diffstat (limited to 'src')
-rw-r--r--src/p11_child/p11_child.c120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/p11_child/p11_child.c b/src/p11_child/p11_child.c
new file mode 100644
index 000000000..957734641
--- /dev/null
+++ b/src/p11_child/p11_child.c
@@ -0,0 +1,120 @@
+
+
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <p11-kit/p11-kit.h>
+#include <p11-kit/iter.h>
+
+
+#define CKA_INVALID ((CK_ULONG)-1)
+
+
+int main(int argc, char *argv[])
+{
+ CK_FUNCTION_LIST **modules = NULL;
+ CK_RV rv;
+ P11KitIter *iter;
+ size_t c;
+ p11_kit_uri *uri;
+ char *uri_string;
+ CK_ATTRIBUTE *cka_id;
+ CK_ATTRIBUTE *cka_class;
+ CK_ATTRIBUTE attr_types[] = {
+ { CKA_ID, },
+ { CKA_CLASS, },
+ { CKA_CERTIFICATE_TYPE, },
+ { CKA_LABEL, },
+ { CKA_VALUE, },
+ { CKA_SUBJECT, },
+ { CKA_ISSUER, },
+ { CKA_SERIAL_NUMBER, },
+ { CKA_TRUSTED, },
+ { CKA_CERTIFICATE_CATEGORY },
+ { CKA_INVALID, },
+ };
+
+
+ modules = p11_kit_modules_load_and_initialize(P11_KIT_MODULE_CRITICAL);
+ if (modules == NULL) {
+ fprintf(stderr, "p11_kit_modules_load failed [%s].\n",
+ p11_kit_message());
+ return -1;
+ }
+
+ iter = p11_kit_iter_new(NULL, 0);
+ if (iter == NULL) {
+ fprintf(stderr, "p11_kit_iter_new failed [%s].\n", p11_kit_message());
+ return -1;
+ }
+
+ p11_kit_iter_begin(iter, modules);
+ while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
+ rv = p11_kit_iter_load_attributes(iter, attr_types,
+ (sizeof(attr_types)/sizeof(CK_ATTRIBUTE)) -1);
+ if (rv != CKR_OK) {
+ fprintf(stderr, "p11_kit_iter_load_attributes failed [%s].\n",
+ p11_kit_message());
+ }
+
+ cka_id = NULL;
+ cka_class = NULL;
+ for (c = 0; attr_types[c].type != CKA_INVALID; c++) {
+ if (attr_types[c].type == CKA_LABEL) {
+ if (attr_types[c].ulValueLen != 0
+ && attr_types[c].pValue != NULL) {
+ fprintf(stderr, "Label [%.*s].\n", (int) attr_types[c].ulValueLen,
+ (char *) attr_types[c].pValue);
+ } else {
+ fprintf(stderr, "Missing label!.\n");
+ }
+ } else if (attr_types[c].type == CKA_ID) {
+ cka_id = attr_types + c;
+ } else if (attr_types[c].type == CKA_CLASS) {
+ cka_class = attr_types + c;
+ }
+ }
+
+ uri = p11_kit_uri_new();
+ if (uri == NULL) {
+ fprintf(stderr, "p11_kit_uri_new failed [%s].\n",
+ p11_kit_message());
+ continue;
+ }
+
+ memcpy(p11_kit_uri_get_token_info(uri), p11_kit_iter_get_token(iter),
+ sizeof (CK_TOKEN_INFO));
+
+ if (cka_id != NULL) {
+ p11_kit_uri_set_attribute(uri, cka_id);
+ }
+ if (cka_class != NULL) {
+ p11_kit_uri_set_attribute(uri, cka_class);
+ }
+
+ rv = p11_kit_uri_format(uri, P11_KIT_URI_FOR_ANY, &uri_string);
+ p11_kit_uri_free(uri);
+ if (rv != P11_KIT_URI_OK) {
+ fprintf(stderr, "p11_kit_uri_format failed [%s].\n",
+ p11_kit_message());
+ continue;
+ }
+
+ fprintf(stderr,"URI [%s].\n", uri_string);
+ free(uri_string);
+
+ for (c = 0; attr_types[c].type != CKA_INVALID; c++) {
+ free(attr_types[c].pValue);
+ attr_types[c].pValue = NULL;
+ }
+ }
+
+ p11_kit_iter_free(iter);
+
+ p11_kit_modules_finalize_and_release(modules);
+
+ return 0;
+}