/security/nss/lib/ckfw/capi/ctoken.c

http://github.com/zpao/v8monkey · C · 246 lines · 186 code · 16 blank · 44 comment · 2 complexity · bb6a762566e8ab49c5951169401470cd MD5 · raw file

  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is the Netscape security libraries.
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Netscape Communications Corporation.
  18. * Portions created by the Initial Developer are Copyright (C) 1994-2000
  19. * the Initial Developer. All Rights Reserved.
  20. * Portions created by Red Hat, Inc, are Copyright (C) 2005
  21. *
  22. * Contributor(s):
  23. * Bob Relyea (rrelyea@redhat.com)
  24. *
  25. * Alternatively, the contents of this file may be used under the terms of
  26. * either the GNU General Public License Version 2 or later (the "GPL"), or
  27. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. * in which case the provisions of the GPL or the LGPL are applicable instead
  29. * of those above. If you wish to allow use of your version of this file only
  30. * under the terms of either the GPL or the LGPL, and not to allow others to
  31. * use your version of this file under the terms of the MPL, indicate your
  32. * decision by deleting the provisions above and replace them with the notice
  33. * and other provisions required by the GPL or the LGPL. If you do not delete
  34. * the provisions above, a recipient may use your version of this file under
  35. * the terms of any one of the MPL, the GPL or the LGPL.
  36. *
  37. * ***** END LICENSE BLOCK ***** */
  38. #ifdef DEBUG
  39. static const char CVS_ID[] = "@(#) $RCSfile: ctoken.c,v $ $Revision: 1.2 $ $Date: 2005/11/15 00:13:58 $";
  40. #endif /* DEBUG */
  41. #include "ckcapi.h"
  42. /*
  43. * ckcapi/ctoken.c
  44. *
  45. * This file implements the NSSCKMDToken object for the
  46. * "nss to capi" cryptoki module.
  47. */
  48. static NSSUTF8 *
  49. ckcapi_mdToken_GetLabel
  50. (
  51. NSSCKMDToken *mdToken,
  52. NSSCKFWToken *fwToken,
  53. NSSCKMDInstance *mdInstance,
  54. NSSCKFWInstance *fwInstance,
  55. CK_RV *pError
  56. )
  57. {
  58. return (NSSUTF8 *)nss_ckcapi_TokenLabel;
  59. }
  60. static NSSUTF8 *
  61. ckcapi_mdToken_GetManufacturerID
  62. (
  63. NSSCKMDToken *mdToken,
  64. NSSCKFWToken *fwToken,
  65. NSSCKMDInstance *mdInstance,
  66. NSSCKFWInstance *fwInstance,
  67. CK_RV *pError
  68. )
  69. {
  70. return (NSSUTF8 *)nss_ckcapi_ManufacturerID;
  71. }
  72. static NSSUTF8 *
  73. ckcapi_mdToken_GetModel
  74. (
  75. NSSCKMDToken *mdToken,
  76. NSSCKFWToken *fwToken,
  77. NSSCKMDInstance *mdInstance,
  78. NSSCKFWInstance *fwInstance,
  79. CK_RV *pError
  80. )
  81. {
  82. return (NSSUTF8 *)nss_ckcapi_TokenModel;
  83. }
  84. static NSSUTF8 *
  85. ckcapi_mdToken_GetSerialNumber
  86. (
  87. NSSCKMDToken *mdToken,
  88. NSSCKFWToken *fwToken,
  89. NSSCKMDInstance *mdInstance,
  90. NSSCKFWInstance *fwInstance,
  91. CK_RV *pError
  92. )
  93. {
  94. return (NSSUTF8 *)nss_ckcapi_TokenSerialNumber;
  95. }
  96. static CK_BBOOL
  97. ckcapi_mdToken_GetIsWriteProtected
  98. (
  99. NSSCKMDToken *mdToken,
  100. NSSCKFWToken *fwToken,
  101. NSSCKMDInstance *mdInstance,
  102. NSSCKFWInstance *fwInstance
  103. )
  104. {
  105. return CK_FALSE;
  106. }
  107. /* fake out Mozilla so we don't try to initialize the token */
  108. static CK_BBOOL
  109. ckcapi_mdToken_GetUserPinInitialized
  110. (
  111. NSSCKMDToken *mdToken,
  112. NSSCKFWToken *fwToken,
  113. NSSCKMDInstance *mdInstance,
  114. NSSCKFWInstance *fwInstance
  115. )
  116. {
  117. return CK_TRUE;
  118. }
  119. static CK_VERSION
  120. ckcapi_mdToken_GetHardwareVersion
  121. (
  122. NSSCKMDToken *mdToken,
  123. NSSCKFWToken *fwToken,
  124. NSSCKMDInstance *mdInstance,
  125. NSSCKFWInstance *fwInstance
  126. )
  127. {
  128. return nss_ckcapi_HardwareVersion;
  129. }
  130. static CK_VERSION
  131. ckcapi_mdToken_GetFirmwareVersion
  132. (
  133. NSSCKMDToken *mdToken,
  134. NSSCKFWToken *fwToken,
  135. NSSCKMDInstance *mdInstance,
  136. NSSCKFWInstance *fwInstance
  137. )
  138. {
  139. return nss_ckcapi_FirmwareVersion;
  140. }
  141. static NSSCKMDSession *
  142. ckcapi_mdToken_OpenSession
  143. (
  144. NSSCKMDToken *mdToken,
  145. NSSCKFWToken *fwToken,
  146. NSSCKMDInstance *mdInstance,
  147. NSSCKFWInstance *fwInstance,
  148. NSSCKFWSession *fwSession,
  149. CK_BBOOL rw,
  150. CK_RV *pError
  151. )
  152. {
  153. return nss_ckcapi_CreateSession(fwSession, pError);
  154. }
  155. static CK_ULONG
  156. ckcapi_mdToken_GetMechanismCount
  157. (
  158. NSSCKMDToken *mdToken,
  159. NSSCKFWToken *fwToken,
  160. NSSCKMDInstance *mdInstance,
  161. NSSCKFWInstance *fwInstance
  162. )
  163. {
  164. return (CK_ULONG)1;
  165. }
  166. static CK_RV
  167. ckcapi_mdToken_GetMechanismTypes
  168. (
  169. NSSCKMDToken *mdToken,
  170. NSSCKFWToken *fwToken,
  171. NSSCKMDInstance *mdInstance,
  172. NSSCKFWInstance *fwInstance,
  173. CK_MECHANISM_TYPE types[]
  174. )
  175. {
  176. types[0] = CKM_RSA_PKCS;
  177. return CKR_OK;
  178. }
  179. static NSSCKMDMechanism *
  180. ckcapi_mdToken_GetMechanism
  181. (
  182. NSSCKMDToken *mdToken,
  183. NSSCKFWToken *fwToken,
  184. NSSCKMDInstance *mdInstance,
  185. NSSCKFWInstance *fwInstance,
  186. CK_MECHANISM_TYPE which,
  187. CK_RV *pError
  188. )
  189. {
  190. if (which != CKM_RSA_PKCS) {
  191. *pError = CKR_MECHANISM_INVALID;
  192. return (NSSCKMDMechanism *)NULL;
  193. }
  194. return (NSSCKMDMechanism *)&nss_ckcapi_mdMechanismRSA;
  195. }
  196. NSS_IMPLEMENT_DATA const NSSCKMDToken
  197. nss_ckcapi_mdToken = {
  198. (void *)NULL, /* etc */
  199. NULL, /* Setup */
  200. NULL, /* Invalidate */
  201. NULL, /* InitToken -- default errs */
  202. ckcapi_mdToken_GetLabel,
  203. ckcapi_mdToken_GetManufacturerID,
  204. ckcapi_mdToken_GetModel,
  205. ckcapi_mdToken_GetSerialNumber,
  206. NULL, /* GetHasRNG -- default is false */
  207. ckcapi_mdToken_GetIsWriteProtected,
  208. NULL, /* GetLoginRequired -- default is false */
  209. ckcapi_mdToken_GetUserPinInitialized,
  210. NULL, /* GetRestoreKeyNotNeeded -- irrelevant */
  211. NULL, /* GetHasClockOnToken -- default is false */
  212. NULL, /* GetHasProtectedAuthenticationPath -- default is false */
  213. NULL, /* GetSupportsDualCryptoOperations -- default is false */
  214. NULL, /* GetMaxSessionCount -- default is CK_UNAVAILABLE_INFORMATION */
  215. NULL, /* GetMaxRwSessionCount -- default is CK_UNAVAILABLE_INFORMATION */
  216. NULL, /* GetMaxPinLen -- irrelevant */
  217. NULL, /* GetMinPinLen -- irrelevant */
  218. NULL, /* GetTotalPublicMemory -- default is CK_UNAVAILABLE_INFORMATION */
  219. NULL, /* GetFreePublicMemory -- default is CK_UNAVAILABLE_INFORMATION */
  220. NULL, /* GetTotalPrivateMemory -- default is CK_UNAVAILABLE_INFORMATION */
  221. NULL, /* GetFreePrivateMemory -- default is CK_UNAVAILABLE_INFORMATION */
  222. ckcapi_mdToken_GetHardwareVersion,
  223. ckcapi_mdToken_GetFirmwareVersion,
  224. NULL, /* GetUTCTime -- no clock */
  225. ckcapi_mdToken_OpenSession,
  226. ckcapi_mdToken_GetMechanismCount,
  227. ckcapi_mdToken_GetMechanismTypes,
  228. ckcapi_mdToken_GetMechanism,
  229. (void *)NULL /* null terminator */
  230. };