1 /* This example code is placed in the public domain. */
4 #include <gnutls/gnutls.h>
5 #include <gnutls/pkcs11.h>
9 #define URL "pkcs11:URL"
12 main (int argc
, char** argv
)
14 gnutls_pkcs11_obj_t
*obj_list
;
15 gnutls_x509_crt_t xcrt
;
16 unsigned int obj_list_size
= 0;
22 ret
= gnutls_pkcs11_obj_list_import_url (NULL
, &obj_list_size
, URL
,
23 GNUTLS_PKCS11_OBJ_ATTR_CRT_WITH_PRIVKEY
,
25 if (ret
< 0 && ret
!= GNUTLS_E_SHORT_MEMORY_BUFFER
)
28 /* no error checking from now on */
29 obj_list
= malloc (sizeof (*obj_list
) * obj_list_size
);
31 gnutls_pkcs11_obj_list_import_url (obj_list
, &obj_list_size
, URL
,
32 GNUTLS_PKCS11_OBJ_ATTR_CRT_WITH_PRIVKEY
,
35 /* now all certificates are in obj_list */
36 for (i
= 0; i
< obj_list_size
; i
++)
39 gnutls_x509_crt_init (&xcrt
);
41 gnutls_x509_crt_import_pkcs11 (xcrt
, obj_list
[i
]);
43 gnutls_x509_crt_print (xcrt
, GNUTLS_CRT_PRINT_FULL
, &cinfo
);
45 fprintf (stdout
, "cert[%d]:\n %s\n\n", i
, cinfo
.data
);
47 gnutls_free (cinfo
.data
);
48 gnutls_x509_crt_deinit (xcrt
);