t-getattribute.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /* t-getattribute.c - Regression test.
  2. Copyright (C) 2006, 2007 g10 Code GmbH
  3. This file is part of Scute.
  4. Scute is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. Scute is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with Scute; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. In addition, as a special exception, g10 Code GmbH gives permission
  16. to link this library: with the Mozilla Foundation's code for
  17. Mozilla (or with modified versions of it that use the same license
  18. as the "Mozilla" code), and distribute the linked executables. You
  19. must obey the GNU General Public License in all respects for all of
  20. the code used other than "Mozilla". If you modify this file, you
  21. may extend this exception to your version of the file, but you are
  22. not obligated to do so. If you do not wish to do so, delete this
  23. exception statement from your version. */
  24. #include <stdio.h>
  25. #include <stdbool.h>
  26. #include <ctype.h>
  27. #include "t-support.h"
  28. /* If printable characters should be output "as-is". */
  29. bool printable;
  30. CK_RV
  31. dump_one (CK_ATTRIBUTE_PTR attr, unsigned char *data, int max_size)
  32. {
  33. int i;
  34. int col;
  35. if (attr->ulValueLen < 0 || attr->ulValueLen > max_size)
  36. return CKR_GENERAL_ERROR;
  37. col = 0;
  38. for (i = 0; i < attr->ulValueLen; i++)
  39. {
  40. if (col == 0)
  41. printf (" ");
  42. if (printable)
  43. {
  44. if (isprint (data[i]))
  45. {
  46. printf ("%c", data[i]);
  47. col++;
  48. }
  49. else
  50. {
  51. printf ("\\x%02x", data[i]);
  52. col += 4;
  53. }
  54. }
  55. else
  56. {
  57. printf ("%02x", data[i]);
  58. col += 2;
  59. }
  60. if (col >= 64)
  61. {
  62. printf ("\n");
  63. col = 0;
  64. }
  65. }
  66. if (col)
  67. printf ("\n");
  68. return 0;
  69. }
  70. CK_RV
  71. dump_object (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object)
  72. {
  73. CK_RV err;
  74. CK_OBJECT_CLASS obj_class;
  75. CK_ATTRIBUTE attr_class = { CKA_CLASS, &obj_class, sizeof (obj_class) };
  76. err = C_GetAttributeValue (session, object, &attr_class, 1);
  77. if (err)
  78. return err;
  79. printf (" Object Class: %lu = ", obj_class);
  80. switch (obj_class)
  81. {
  82. #define MAX_CERT_LEN 4096
  83. case CKO_CERTIFICATE:
  84. {
  85. CK_CERTIFICATE_TYPE cert_type;
  86. CK_BBOOL cert_token;
  87. CK_BBOOL cert_private;
  88. CK_BBOOL cert_modifiable;
  89. CK_BYTE cert_label[MAX_CERT_LEN];
  90. CK_BBOOL cert_trusted;
  91. CK_ULONG cert_cc;
  92. CK_BYTE cert_check[3];
  93. CK_DATE cert_sdate;
  94. CK_DATE cert_edate;
  95. CK_BYTE cert_subject[MAX_CERT_LEN];
  96. CK_BYTE cert_id[MAX_CERT_LEN];
  97. CK_BYTE cert_issuer[MAX_CERT_LEN];
  98. CK_BYTE cert_serial[MAX_CERT_LEN];
  99. CK_BYTE cert_value[MAX_CERT_LEN];
  100. CK_ULONG cert_jm;
  101. /* Note that the order is encoded below in the various length
  102. checks. */
  103. CK_ATTRIBUTE cert_attr[]
  104. = { { CKA_CERTIFICATE_TYPE, &cert_type, sizeof (cert_type) },
  105. { CKA_TOKEN, &cert_token, sizeof (cert_token) },
  106. { CKA_PRIVATE, &cert_private, sizeof (cert_private) },
  107. { CKA_MODIFIABLE, &cert_modifiable, sizeof (cert_modifiable) },
  108. { CKA_LABEL, &cert_label, sizeof (cert_label) },
  109. { CKA_TRUSTED, &cert_trusted, sizeof (cert_trusted) },
  110. { CKA_CERTIFICATE_CATEGORY, &cert_cc, sizeof (cert_cc) },
  111. { CKA_CHECK_VALUE, &cert_check, sizeof (cert_check) },
  112. { CKA_START_DATE, &cert_sdate, sizeof (cert_sdate) },
  113. { CKA_END_DATE, &cert_edate, sizeof (cert_edate) },
  114. { CKA_SUBJECT, &cert_subject, sizeof (cert_subject) },
  115. { CKA_ID, &cert_id, sizeof (cert_id) },
  116. { CKA_ISSUER, &cert_issuer, sizeof (cert_issuer) },
  117. { CKA_SERIAL_NUMBER, &cert_serial, sizeof (cert_serial) },
  118. { CKA_VALUE, cert_value, sizeof (cert_value) },
  119. { CKA_URL, NULL, 0 },
  120. { CKA_HASH_OF_SUBJECT_PUBLIC_KEY, NULL, 0 },
  121. { CKA_HASH_OF_ISSUER_PUBLIC_KEY, NULL, 0 },
  122. { CKA_JAVA_MIDP_SECURITY_DOMAIN, &cert_jm, sizeof (cert_jm) } };
  123. printf ("CKO_CERTIFICATE\n");
  124. err = C_GetAttributeValue (session, object,
  125. cert_attr, DIM (cert_attr));
  126. if (err)
  127. return err;
  128. fail_if_err ((cert_attr[0].ulValueLen != sizeof (cert_type)) ?
  129. CKR_GENERAL_ERROR : 0);
  130. printf (" Certificate Type: %lu = ", cert_type);
  131. switch (cert_type)
  132. {
  133. case CKC_X_509:
  134. printf ("CKC_X_509");
  135. break;
  136. case CKC_WTLS:
  137. printf ("CKC_WTLS");
  138. break;
  139. case CKC_X_509_ATTR_CERT:
  140. printf ("CKC_X_509_ATTR_CERT");
  141. break;
  142. default:
  143. printf ("(unknown");
  144. break;
  145. }
  146. printf ("\n");
  147. fail_if_err ((cert_attr[1].ulValueLen != sizeof (cert_token)) ?
  148. CKR_GENERAL_ERROR : 0);
  149. printf (" Certificate Token: %s\n",
  150. cert_token ? "true" : "false");
  151. fail_if_err ((cert_attr[2].ulValueLen != sizeof (cert_private)) ?
  152. CKR_GENERAL_ERROR : 0);
  153. printf (" Certificate Private: %s\n",
  154. cert_private ? "true" : "false");
  155. fail_if_err ((cert_attr[3].ulValueLen != sizeof (cert_modifiable)) ?
  156. CKR_GENERAL_ERROR : 0);
  157. printf (" Certificate Modifiable: %s\n",
  158. cert_modifiable ? "true" : "false");
  159. printf (" Certificate Label: Length %lu\n",
  160. cert_attr[4].ulValueLen);
  161. err = dump_one (&cert_attr[4], cert_label, sizeof (cert_label));
  162. fail_if_err (err);
  163. fail_if_err ((cert_attr[5].ulValueLen != sizeof (cert_trusted)) ?
  164. CKR_GENERAL_ERROR : 0);
  165. printf (" Certificate Trusted: %s\n",
  166. cert_trusted ? "true" : "false");
  167. fail_if_err ((cert_attr[6].ulValueLen != sizeof (cert_cc)) ?
  168. CKR_GENERAL_ERROR : 0);
  169. printf (" Certificate Category: %lu = ", cert_cc);
  170. switch (cert_cc)
  171. {
  172. case 0:
  173. printf ("unspecified");
  174. break;
  175. case 1:
  176. printf ("token user");
  177. break;
  178. case 2:
  179. printf ("authority");
  180. break;
  181. case 3:
  182. printf ("other entity");
  183. break;
  184. default:
  185. printf ("(unknown)");
  186. break;
  187. }
  188. printf ("\n");
  189. fail_if_err ((cert_attr[7].ulValueLen != sizeof (cert_check)) ?
  190. CKR_GENERAL_ERROR : 0);
  191. printf (" Certificate Check Value: %02x%02x%02x\n",
  192. cert_check[0], cert_check[1], cert_check[2]);
  193. fail_if_err ((cert_attr[8].ulValueLen != sizeof (cert_sdate)) ?
  194. CKR_GENERAL_ERROR : 0);
  195. printf (" Certificate Start Date: %.4s/%.2s/%.2s\n",
  196. cert_sdate.year, cert_sdate.month, cert_sdate.day);
  197. fail_if_err ((cert_attr[9].ulValueLen != sizeof (cert_edate)) ?
  198. CKR_GENERAL_ERROR : 0);
  199. printf (" Certificate End Date: %.4s/%.2s/%.2s\n",
  200. cert_edate.year, cert_edate.month, cert_edate.day);
  201. printf (" Certificate Subject: Length %lu\n",
  202. cert_attr[10].ulValueLen);
  203. err = dump_one (&cert_attr[10], cert_subject, sizeof (cert_subject));
  204. fail_if_err (err);
  205. printf (" Certificate ID: Length %lu\n",
  206. cert_attr[11].ulValueLen);
  207. err = dump_one (&cert_attr[11], cert_id, sizeof (cert_id));
  208. fail_if_err (err);
  209. printf (" Certificate Issuer: Length %lu\n",
  210. cert_attr[12].ulValueLen);
  211. err = dump_one (&cert_attr[12], cert_issuer, sizeof (cert_issuer));
  212. fail_if_err (err);
  213. printf (" Certificate Serial Number: Length %lu\n",
  214. cert_attr[13].ulValueLen);
  215. err = dump_one (&cert_attr[13], cert_serial, sizeof (cert_serial));
  216. fail_if_err (err);
  217. printf (" Certificate Value: Length %lu\n",
  218. cert_attr[14].ulValueLen);
  219. err = dump_one (&cert_attr[14], cert_value, sizeof (cert_value));
  220. fail_if_err (err);
  221. fail_if_err ((cert_attr[15].ulValueLen != 0) ? CKR_GENERAL_ERROR : 0);
  222. fail_if_err ((cert_attr[16].ulValueLen != 0) ? CKR_GENERAL_ERROR : 0);
  223. fail_if_err ((cert_attr[17].ulValueLen != 0) ? CKR_GENERAL_ERROR : 0);
  224. fail_if_err ((cert_attr[18].ulValueLen != sizeof (cert_jm)) ?
  225. CKR_GENERAL_ERROR : 0);
  226. printf (" Certificate Java MIDP Security Domain: %lu = ", cert_jm);
  227. switch (cert_jm)
  228. {
  229. case 0:
  230. printf ("unspecified");
  231. break;
  232. case 1:
  233. printf ("manufacturer");
  234. break;
  235. case 2:
  236. printf ("operator");
  237. break;
  238. case 3:
  239. printf ("third party");
  240. break;
  241. default:
  242. printf ("(unknown)");
  243. break;
  244. }
  245. printf ("\n");
  246. }
  247. break;
  248. case CKO_PRIVATE_KEY:
  249. {
  250. CK_KEY_TYPE key_type;
  251. CK_BBOOL key_token;
  252. CK_BBOOL key_private;
  253. CK_BBOOL key_modifiable;
  254. CK_BYTE key_label[MAX_CERT_LEN];
  255. CK_BYTE key_id[MAX_CERT_LEN];
  256. CK_DATE key_sdate;
  257. CK_DATE key_edate;
  258. CK_BBOOL key_derive;
  259. CK_BBOOL key_local;
  260. CK_MECHANISM_TYPE key_gen;
  261. CK_MECHANISM_TYPE key_mechanisms[1]; /* FIXME, hard-coded constant. */
  262. CK_BYTE key_subject[MAX_CERT_LEN];
  263. CK_BBOOL key_sensitive;
  264. CK_BBOOL key_decrypt;
  265. CK_BBOOL key_sign;
  266. CK_BBOOL key_sign_recover;
  267. CK_BBOOL key_unwrap;
  268. CK_BBOOL key_extractable;
  269. CK_BBOOL key_always_sensitive;
  270. CK_BBOOL key_never_extractable;
  271. CK_BBOOL key_wrap_with_trusted;
  272. CK_BBOOL key_always_authenticate;
  273. CK_BYTE key_modulus[MAX_CERT_LEN];
  274. CK_BYTE key_public_exp[MAX_CERT_LEN];
  275. /* Note that the order is encoded below in the various length
  276. checks. */
  277. CK_ATTRIBUTE key_attr[]
  278. = { { CKA_KEY_TYPE, &key_type, sizeof (key_type) },
  279. { CKA_TOKEN, &key_token, sizeof (key_token) },
  280. { CKA_PRIVATE, &key_private, sizeof (key_private) },
  281. { CKA_MODIFIABLE, &key_modifiable, sizeof (key_modifiable) },
  282. { CKA_LABEL, &key_label, sizeof (key_label) },
  283. { CKA_ID, &key_id, sizeof (key_id) },
  284. { CKA_START_DATE, &key_sdate, sizeof (key_sdate) },
  285. { CKA_END_DATE, &key_edate, sizeof (key_edate) },
  286. { CKA_DERIVE, &key_derive, sizeof (key_derive) },
  287. { CKA_LOCAL, &key_local, sizeof (key_local) },
  288. { CKA_KEY_GEN_MECHANISM, &key_gen, sizeof (key_gen) },
  289. { CKA_ALLOWED_MECHANISMS, &key_mechanisms,
  290. sizeof (key_mechanisms) },
  291. { CKA_SUBJECT, &key_subject, sizeof (key_subject) },
  292. { CKA_SENSITIVE, &key_sensitive, sizeof (key_sensitive) },
  293. { CKA_DECRYPT, &key_decrypt, sizeof (key_decrypt) },
  294. { CKA_SIGN, &key_sign, sizeof (key_sign) },
  295. { CKA_SIGN_RECOVER, &key_sign_recover,
  296. sizeof (key_sign_recover) },
  297. { CKA_UNWRAP, &key_unwrap, sizeof (key_unwrap) },
  298. { CKA_EXTRACTABLE, &key_extractable, sizeof (key_extractable) },
  299. { CKA_ALWAYS_SENSITIVE, &key_always_sensitive,
  300. sizeof (key_always_sensitive) },
  301. { CKA_NEVER_EXTRACTABLE, &key_never_extractable,
  302. sizeof (key_never_extractable) },
  303. { CKA_WRAP_WITH_TRUSTED, &key_wrap_with_trusted,
  304. sizeof (key_wrap_with_trusted) },
  305. { CKA_UNWRAP_TEMPLATE, NULL, 0 },
  306. { CKA_ALWAYS_AUTHENTICATE, &key_always_authenticate,
  307. sizeof (key_always_authenticate) },
  308. { CKA_MODULUS, &key_modulus, sizeof (key_modulus) },
  309. { CKA_PUBLIC_EXPONENT, &key_public_exp,
  310. sizeof (key_public_exp) } };
  311. printf ("CKO_PRIVATE_KEY\n");
  312. err = C_GetAttributeValue (session, object,
  313. key_attr, DIM (key_attr));
  314. if (err)
  315. return err;
  316. fail_if_err ((key_attr[0].ulValueLen != sizeof (key_type)) ?
  317. CKR_GENERAL_ERROR : 0);
  318. printf (" Key Type: %lu = ", key_type);
  319. switch (key_type)
  320. {
  321. case CKK_RSA:
  322. printf ("CKK_RSA");
  323. break;
  324. case CKK_DSA:
  325. printf ("CKK_DSA");
  326. break;
  327. default:
  328. printf ("(unknown");
  329. break;
  330. }
  331. printf ("\n");
  332. fail_if_err ((key_attr[1].ulValueLen != sizeof (key_token)) ?
  333. CKR_GENERAL_ERROR : 0);
  334. printf (" Key Token: %s\n",
  335. key_token ? "true" : "false");
  336. fail_if_err ((key_attr[2].ulValueLen != sizeof (key_private)) ?
  337. CKR_GENERAL_ERROR : 0);
  338. printf (" Key Private: %s\n",
  339. key_private ? "true" : "false");
  340. fail_if_err ((key_attr[3].ulValueLen != sizeof (key_modifiable)) ?
  341. CKR_GENERAL_ERROR : 0);
  342. printf (" Key Modifiable: %s\n",
  343. key_modifiable ? "true" : "false");
  344. printf (" Key Label: Length %lu\n",
  345. key_attr[4].ulValueLen);
  346. err = dump_one (&key_attr[4], key_label, sizeof (key_label));
  347. fail_if_err (err);
  348. printf (" Key ID: Length %lu\n",
  349. key_attr[5].ulValueLen);
  350. err = dump_one (&key_attr[5], key_id, sizeof (key_id));
  351. fail_if_err (err);
  352. fail_if_err ((key_attr[6].ulValueLen != sizeof (key_sdate)) ?
  353. CKR_GENERAL_ERROR : 0);
  354. printf (" Key Start Date: %.4s/%.2s/%.2s\n",
  355. key_sdate.year, key_sdate.month, key_sdate.day);
  356. fail_if_err ((key_attr[7].ulValueLen != sizeof (key_edate)) ?
  357. CKR_GENERAL_ERROR : 0);
  358. printf (" Key End Date: %.4s/%.2s/%.2s\n",
  359. key_edate.year, key_edate.month, key_edate.day);
  360. fail_if_err ((key_attr[8].ulValueLen != sizeof (key_derive)) ?
  361. CKR_GENERAL_ERROR : 0);
  362. printf (" Key Derive: %s\n",
  363. key_derive ? "true" : "false");
  364. fail_if_err ((key_attr[9].ulValueLen != sizeof (key_local)) ?
  365. CKR_GENERAL_ERROR : 0);
  366. printf (" Key Local: %s\n",
  367. key_local ? "true" : "false");
  368. fail_if_err ((key_attr[10].ulValueLen != sizeof (key_gen)) ?
  369. CKR_GENERAL_ERROR : 0);
  370. /* FIXME: Print Mechanism. */
  371. printf (" Key Gen Mechanism: %lu\n", key_gen);
  372. /* FIXME: Print supported mechanisms. 11 */
  373. printf (" Key Subject: Length %lu\n",
  374. key_attr[12].ulValueLen);
  375. err = dump_one (&key_attr[12], key_subject, sizeof (key_subject));
  376. fail_if_err (err);
  377. fail_if_err ((key_attr[13].ulValueLen != sizeof (key_sensitive)) ?
  378. CKR_GENERAL_ERROR : 0);
  379. printf (" Key Sensitive: %s\n",
  380. key_sensitive ? "true" : "false");
  381. fail_if_err ((key_attr[14].ulValueLen != sizeof (key_decrypt)) ?
  382. CKR_GENERAL_ERROR : 0);
  383. printf (" Key Decrypt: %s\n",
  384. key_decrypt ? "true" : "false");
  385. fail_if_err ((key_attr[15].ulValueLen != sizeof (key_sign)) ?
  386. CKR_GENERAL_ERROR : 0);
  387. printf (" Key Sign: %s\n",
  388. key_sign ? "true" : "false");
  389. fail_if_err ((key_attr[16].ulValueLen != sizeof (key_sign_recover)) ?
  390. CKR_GENERAL_ERROR : 0);
  391. printf (" Key Sign Recover: %s\n",
  392. key_sign_recover ? "true" : "false");
  393. fail_if_err ((key_attr[17].ulValueLen != sizeof (key_unwrap)) ?
  394. CKR_GENERAL_ERROR : 0);
  395. printf (" Key Unwrap: %s\n",
  396. key_unwrap ? "true" : "false");
  397. fail_if_err ((key_attr[18].ulValueLen != sizeof (key_extractable)) ?
  398. CKR_GENERAL_ERROR : 0);
  399. printf (" Key Extractable: %s\n",
  400. key_extractable ? "true" : "false");
  401. fail_if_err ((key_attr[19].ulValueLen
  402. != sizeof (key_always_sensitive)) ?
  403. CKR_GENERAL_ERROR : 0);
  404. printf (" Key Always Sensitive: %s\n",
  405. key_always_sensitive ? "true" : "false");
  406. fail_if_err ((key_attr[20].ulValueLen
  407. != sizeof (key_never_extractable)) ?
  408. CKR_GENERAL_ERROR : 0);
  409. printf (" Key Never Extractable: %s\n",
  410. key_never_extractable ? "true" : "false");
  411. fail_if_err ((key_attr[21].ulValueLen
  412. != sizeof (key_wrap_with_trusted)) ?
  413. CKR_GENERAL_ERROR : 0);
  414. printf (" Key Wrap With Trusted: %s\n",
  415. key_wrap_with_trusted ? "true" : "false");
  416. fail_if_err ((key_attr[22].ulValueLen != 0) ? CKR_GENERAL_ERROR : 0);
  417. fail_if_err ((key_attr[23].ulValueLen
  418. != sizeof (key_always_authenticate)) ?
  419. CKR_GENERAL_ERROR : 0);
  420. printf (" Key Always Authenticate: %s\n",
  421. key_always_authenticate ? "true" : "false");
  422. printf (" Key Modulus: Length %lu\n",
  423. key_attr[24].ulValueLen);
  424. err = dump_one (&key_attr[24], key_modulus, sizeof (key_modulus));
  425. fail_if_err (err);
  426. printf (" Key Subject: Length %lu\n",
  427. key_attr[25].ulValueLen);
  428. err = dump_one (&key_attr[25], key_public_exp,
  429. sizeof (key_public_exp));
  430. fail_if_err (err);
  431. }
  432. break;
  433. default:
  434. printf ("(unknown)\n");
  435. }
  436. return 0;
  437. }
  438. int
  439. main (int argc, char *argv[])
  440. {
  441. CK_RV err;
  442. CK_SLOT_ID_PTR slots;
  443. CK_ULONG slots_count;
  444. int i;
  445. if (argc > 1 && !strcmp ("--printable", argv[1]))
  446. printable = true;
  447. init_cryptoki ();
  448. err = C_GetSlotList (true, NULL, &slots_count);
  449. fail_if_err (err);
  450. if (slots_count == 0)
  451. {
  452. printf ("Skipping test because no token is present.\n");
  453. return 0;
  454. }
  455. printf ("Number of slots with tokens: %lu\n", slots_count);
  456. slots = malloc (sizeof (CK_SLOT_ID) * slots_count);
  457. if (!slots)
  458. fail_if_err (CKR_HOST_MEMORY);
  459. err = C_GetSlotList (true, slots, &slots_count);
  460. fail_if_err (err);
  461. for (i = 0; i < slots_count; i++)
  462. {
  463. CK_SESSION_HANDLE session;
  464. CK_OBJECT_HANDLE object;
  465. CK_ULONG count;
  466. printf ("%2i. Slot ID %lu\n", i, slots[i]);
  467. err = C_OpenSession (slots[i], CKF_SERIAL_SESSION, NULL, NULL,
  468. &session);
  469. fail_if_err (err);
  470. printf (" Session ID: %lu\n", session);
  471. err = C_FindObjectsInit (session, NULL, 0);
  472. fail_if_err (err);
  473. do
  474. {
  475. err = C_FindObjects (session, &object, 1, &count);
  476. fail_if_err (err);
  477. if (count)
  478. {
  479. printf (" Object Handle: %lu\n", object);
  480. err = dump_object (session, object);
  481. fail_if_err (err);
  482. }
  483. }
  484. while (count);
  485. err = C_FindObjectsFinal (session);
  486. fail_if_err (err);
  487. err = C_CloseSession (session);
  488. fail_if_err (err);
  489. }
  490. return 0;
  491. }