p11-gettokeninfo.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* p11-gettokeninfo.c - Cryptoki implementation.
  2. Copyright (C) 2006 g10 Code GmbH
  3. This file is part of Scute[1].
  4. [1] Derived from the RSA Security Inc. PKCS #11 Cryptographic Token
  5. Interface (Cryptoki).
  6. Scute is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. Scute is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Scute; if not, write to the Free Software Foundation,
  16. Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. In addition, as a special exception, g10 Code GmbH gives permission
  18. to link this library: with the Mozilla Fondations's code for
  19. Mozilla (or with modified versions of it that use the same license
  20. as the "Mozilla" code), and distribute the linked executables. You
  21. must obey the GNU General Public License in all respects for all of
  22. the code used other than "Mozilla". If you modify this file, you
  23. may extend this exception to your version of the file, but you are
  24. not obligated to do so. If you do not wish to do so, delete this
  25. exception statement from your version. */
  26. #if HAVE_CONFIG_H
  27. #include <config.h>
  28. #endif
  29. #include "cryptoki.h"
  30. #include "locking.h"
  31. #include "support.h"
  32. #include "settings.h"
  33. #include "slots.h"
  34. CK_DEFINE_FUNCTION(CK_RV, C_GetTokenInfo)
  35. (CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo)
  36. {
  37. CK_RV err = CKR_OK;
  38. slot_iterator_t slot;
  39. int len;
  40. int max;
  41. err = scute_global_lock ();
  42. if (err)
  43. return err;
  44. err = slots_lookup (slotID, &slot);
  45. if (err)
  46. goto out;
  47. if (!slot_token_present (slot))
  48. {
  49. err = CKR_TOKEN_NOT_PRESENT;
  50. goto out;
  51. }
  52. scute_copy_string (pInfo->label, slot_token_label (slot), 32);
  53. scute_copy_string (pInfo->manufacturerID,
  54. slot_token_manufacturer (slot), 32);
  55. scute_copy_string (pInfo->model, slot_token_application (slot), 16);
  56. len = slot_token_serial (slot, pInfo->serialNumber);
  57. while (len < 16)
  58. pInfo->serialNumber[len++] == ' ';
  59. pInfo->flags = CKF_TOKEN_INITIALIZED
  60. | CKF_PROTECTED_AUTHENTICATION_PATH | CKF_WRITE_PROTECTED
  61. | CKF_USER_PIN_INITIALIZED;
  62. /* FIXME: Support this later: CKF_RNG.
  63. FIXME: CKF_USER_PIN_INITIALIZED only if PIN is not default pin?
  64. FIXME: CKF_LOGIN_REQUIRED needed? We could implement login via
  65. the "SCD CHECKPIN" command. I am not sure how this mixes with
  66. CKF_PROTECTED_AUTHENTICATION_PATH.
  67. Not supported:
  68. CKF_RESTORE_KEY_NOT_NEEDED, CKF_DUAL_CRYPTO_OPERATIONS.
  69. FIXME: We can support those, but do we worry about SO operations?
  70. CKF_SO_PIN_COUNT_LOW, CKF_SO_PIN_FINAL_TRY, CKF_SO_PIN_LOCKED.
  71. Not supported: CKF_USER_PIN_TO_BE_CHANGED, CKF_SO_PIN_TO_BE_CHANGED. */
  72. slot_token_pincount (slot, &max, &len);
  73. if (len < max)
  74. pInfo->flags |= CKF_USER_PIN_COUNT_LOW;
  75. if (len == 1)
  76. pInfo->flags |= CKF_USER_PIN_FINAL_TRY;
  77. else if (len == 0)
  78. pInfo->flags |= CKF_USER_PIN_LOCKED;
  79. pInfo->ulMaxSessionCount = CK_UNAVAILABLE_INFORMATION;
  80. pInfo->ulSessionCount = CK_UNAVAILABLE_INFORMATION;
  81. pInfo->ulMaxRwSessionCount = CK_UNAVAILABLE_INFORMATION;
  82. pInfo->ulRwSessionCount = CK_UNAVAILABLE_INFORMATION;
  83. slot_token_maxpinlen (slot, &pInfo->ulMaxPinLen, &pInfo->ulMinPinLen);
  84. /* FIXME: Get the data from SCD? */
  85. pInfo->ulTotalPublicMemory = CK_UNAVAILABLE_INFORMATION;
  86. pInfo->ulFreePublicMemory = CK_UNAVAILABLE_INFORMATION;
  87. pInfo->ulTotalPrivateMemory = CK_UNAVAILABLE_INFORMATION;
  88. pInfo->ulFreePrivateMemory = CK_UNAVAILABLE_INFORMATION;
  89. slot_token_version (slot, &pInfo->hardwareVersion.major,
  90. &pInfo->hardwareVersion.minor,
  91. &pInfo->firmwareVersion.major,
  92. &pInfo->firmwareVersion.minor);
  93. scute_copy_string (pInfo->utcTime, "0000000000000000", 16);
  94. out:
  95. scute_global_unlock ();
  96. return err;
  97. }