slots.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* slots.h - Slot management interface.
  2. Copyright (C) 2006 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. #ifndef SLOTS_H
  25. #define SLOTS_H 1
  26. #include <stdbool.h>
  27. #include "cryptoki.h"
  28. /* The slot login status. */
  29. typedef enum
  30. {
  31. SLOT_LOGIN_PUBLIC = 0,
  32. SLOT_LOGIN_USER = 1,
  33. SLOT_LOGIN_SO = 2,
  34. } slot_login_t;
  35. /* A slot pointer. */
  36. typedef CK_SLOT_ID slot_iterator_t;
  37. /* A mechanism pointer. */
  38. typedef int mechanism_iterator_t;
  39. /* An object pointer. */
  40. typedef CK_OBJECT_HANDLE object_iterator_t;
  41. /* A session pointer. */
  42. typedef int session_iterator_t;
  43. /* Initialize the slot list. */
  44. CK_RV scute_slots_initialize (void);
  45. /* Finalize the slot list. */
  46. void scute_slots_finalize (void);
  47. /* Update the slot list by finding new devices. Please note that
  48. Mozilla NSS currently assumes that the slot list never shrinks (see
  49. TODO file for a discussion). This is the only function allowed to
  50. manipulate the slot list. */
  51. CK_RV slots_update (void);
  52. /* Update the slot SLOT. */
  53. CK_RV slots_update_slot (slot_iterator_t id);
  54. /* Begin iterating over the list of slots. If succeeds, will be
  55. followed up by a slot_iterate_end. */
  56. CK_RV slots_iterate_first (slot_iterator_t *slot);
  57. /* Continue iterating over the list of slots. */
  58. CK_RV slots_iterate_next (slot_iterator_t *slot);
  59. /* Return true iff the previous slot was the last one. */
  60. bool slots_iterate_last (slot_iterator_t *slot);
  61. /* Acquire the slot for the slot id ID. */
  62. CK_RV slots_lookup (CK_SLOT_ID id, slot_iterator_t *slot);
  63. /* Return true iff a token is present in slot SLOT. */
  64. bool slot_token_present (slot_iterator_t slot);
  65. /* Return the token label. */
  66. char *slot_token_label (slot_iterator_t id);
  67. /* Get the manufacturer of the token. */
  68. char *slot_token_manufacturer (slot_iterator_t id);
  69. /* Get the manufacturer of the token. */
  70. char *slot_token_application (slot_iterator_t id);
  71. /* Get the serial number of the token. Must not write more than 16
  72. bytes starting from DST. */
  73. int slot_token_serial (slot_iterator_t id, char *dst);
  74. /* Get the manufacturer of the token. */
  75. void slot_token_version (slot_iterator_t id,
  76. CK_BYTE *hw_major, CK_BYTE *hw_minor,
  77. CK_BYTE *fw_major, CK_BYTE *fw_minor);
  78. /* Get the maximum and minimum pin length. */
  79. void slot_token_maxpinlen (slot_iterator_t id, CK_ULONG *max, CK_ULONG *min);
  80. /* Get the maximum and the actual pin count. */
  81. void slot_token_pincount (slot_iterator_t id, int *max, int *len);
  82. /* Return the ID of slot SLOT. */
  83. CK_SLOT_ID slot_get_id (slot_iterator_t slot);
  84. /* Begin iterating over the list of mechanisms. If succeeds, will be
  85. followed up by a slot_iterate_end. */
  86. CK_RV mechanisms_iterate_first (slot_iterator_t id,
  87. mechanism_iterator_t *mechanism);
  88. /* Continue iterating over the list of mechanisms. */
  89. CK_RV mechanisms_iterate_next (slot_iterator_t id,
  90. mechanism_iterator_t *mechanism);
  91. /* Return true iff the previous slot was the last one. */
  92. bool mechanisms_iterate_last (slot_iterator_t id,
  93. mechanism_iterator_t *mechanisms);
  94. /* Acquire the mechanism TYPE for the slot id ID. */
  95. CK_RV mechanisms_lookup (CK_SLOT_ID id, mechanism_iterator_t *mechanism,
  96. CK_MECHANISM_TYPE type);
  97. /* Return the type of mechanism MID in slot ID. */
  98. CK_MECHANISM_TYPE mechanism_get_type (slot_iterator_t id,
  99. mechanism_iterator_t mid);
  100. /* Return the info of mechanism MID. */
  101. CK_MECHANISM_INFO_PTR mechanism_get_info (slot_iterator_t id,
  102. mechanism_iterator_t mid);
  103. /* Create a new session. */
  104. CK_RV slot_create_session (slot_iterator_t id, session_iterator_t *session,
  105. bool rw);
  106. /* Look up session. */
  107. CK_RV slots_lookup_session (CK_SESSION_HANDLE sid, slot_iterator_t *id,
  108. session_iterator_t *session_id);
  109. /* Close the session. */
  110. CK_RV slot_close_session (slot_iterator_t id, session_iterator_t sid);
  111. /* Close all sessions. */
  112. CK_RV slot_close_all_sessions (slot_iterator_t id);
  113. /* Get the RW flag from the session SID in slot ID. */
  114. bool session_get_rw (slot_iterator_t id, session_iterator_t sid);
  115. /* Get the login state from the slot ID. */
  116. slot_login_t slot_get_status (slot_iterator_t id);
  117. /* Begin iterating over the list of objects. If succeeds, will be
  118. followed up by a slot_iterate_end. */
  119. CK_RV objects_iterate_first (slot_iterator_t id, object_iterator_t *object);
  120. /* Continue iterating over the list of objects. */
  121. CK_RV objects_iterate_next (slot_iterator_t id, object_iterator_t *object);
  122. /* Return true iff the previous slot was the last one. */
  123. bool objects_iterate_last (slot_iterator_t id, object_iterator_t *object);
  124. /* Return the max. number of objects in the slot. May overcount
  125. somewhat. */
  126. CK_RV slot_get_object_count (slot_iterator_t id, int *nr);
  127. /* Get the object information for object OBJECT_ID in slot ID. */
  128. CK_RV slot_get_object (slot_iterator_t id, object_iterator_t object_id,
  129. CK_ATTRIBUTE_PTR *obj, CK_ULONG *obj_count);
  130. /* Set the result of a search for session SID in slot ID to
  131. SEARCH_RESULT and SEARCH_RESULT_LEN. */
  132. CK_RV session_set_search_result (slot_iterator_t id, session_iterator_t sid,
  133. object_iterator_t *search_result,
  134. int search_result_len);
  135. /* Get the stored search result for the session SID in slot ID. */
  136. CK_RV session_get_search_result (slot_iterator_t id, session_iterator_t sid,
  137. object_iterator_t **search_result,
  138. int *search_result_len);
  139. /* Set the signing key for session SID in slot ID to KEY. */
  140. CK_RV session_set_signing_key (slot_iterator_t id, session_iterator_t sid,
  141. object_iterator_t key);
  142. CK_RV session_sign (slot_iterator_t id, session_iterator_t sid,
  143. CK_BYTE_PTR pData, CK_ULONG ulDataLen,
  144. CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen);
  145. #endif /* !SLOTS_H */