PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 39#ifdef DEBUG
 40static const char CVS_ID[] = "@(#) $RCSfile: ctoken.c,v $ $Revision: 1.2 $ $Date: 2005/11/15 00:13:58 $";
 41#endif /* DEBUG */
 42
 43#include "ckcapi.h"
 44
 45/*
 46 * ckcapi/ctoken.c
 47 *
 48 * This file implements the NSSCKMDToken object for the
 49 * "nss to capi" cryptoki module.
 50 */
 51
 52static NSSUTF8 *
 53ckcapi_mdToken_GetLabel
 54(
 55  NSSCKMDToken *mdToken,
 56  NSSCKFWToken *fwToken,
 57  NSSCKMDInstance *mdInstance,
 58  NSSCKFWInstance *fwInstance,
 59  CK_RV *pError
 60)
 61{
 62  return (NSSUTF8 *)nss_ckcapi_TokenLabel;
 63}
 64
 65static NSSUTF8 *
 66ckcapi_mdToken_GetManufacturerID
 67(
 68  NSSCKMDToken *mdToken,
 69  NSSCKFWToken *fwToken,
 70  NSSCKMDInstance *mdInstance,
 71  NSSCKFWInstance *fwInstance,
 72  CK_RV *pError
 73)
 74{
 75  return (NSSUTF8 *)nss_ckcapi_ManufacturerID;
 76}
 77
 78static NSSUTF8 *
 79ckcapi_mdToken_GetModel
 80(
 81  NSSCKMDToken *mdToken,
 82  NSSCKFWToken *fwToken,
 83  NSSCKMDInstance *mdInstance,
 84  NSSCKFWInstance *fwInstance,
 85  CK_RV *pError
 86)
 87{
 88  return (NSSUTF8 *)nss_ckcapi_TokenModel;
 89}
 90
 91static NSSUTF8 *
 92ckcapi_mdToken_GetSerialNumber
 93(
 94  NSSCKMDToken *mdToken,
 95  NSSCKFWToken *fwToken,
 96  NSSCKMDInstance *mdInstance,
 97  NSSCKFWInstance *fwInstance,
 98  CK_RV *pError
 99)
100{
101  return (NSSUTF8 *)nss_ckcapi_TokenSerialNumber;
102}
103
104static CK_BBOOL
105ckcapi_mdToken_GetIsWriteProtected
106(
107  NSSCKMDToken *mdToken,
108  NSSCKFWToken *fwToken,
109  NSSCKMDInstance *mdInstance,
110  NSSCKFWInstance *fwInstance
111)
112{
113  return CK_FALSE;
114}
115
116/* fake out Mozilla so we don't try to initialize the token */
117static CK_BBOOL
118ckcapi_mdToken_GetUserPinInitialized
119(
120  NSSCKMDToken *mdToken,
121  NSSCKFWToken *fwToken,
122  NSSCKMDInstance *mdInstance,
123  NSSCKFWInstance *fwInstance
124)
125{
126  return CK_TRUE;
127}
128
129static CK_VERSION
130ckcapi_mdToken_GetHardwareVersion
131(
132  NSSCKMDToken *mdToken,
133  NSSCKFWToken *fwToken,
134  NSSCKMDInstance *mdInstance,
135  NSSCKFWInstance *fwInstance
136)
137{
138  return nss_ckcapi_HardwareVersion;
139}
140
141static CK_VERSION
142ckcapi_mdToken_GetFirmwareVersion
143(
144  NSSCKMDToken *mdToken,
145  NSSCKFWToken *fwToken,
146  NSSCKMDInstance *mdInstance,
147  NSSCKFWInstance *fwInstance
148)
149{
150  return nss_ckcapi_FirmwareVersion;
151}
152
153static NSSCKMDSession *
154ckcapi_mdToken_OpenSession
155(
156  NSSCKMDToken *mdToken,
157  NSSCKFWToken *fwToken,
158  NSSCKMDInstance *mdInstance,
159  NSSCKFWInstance *fwInstance,
160  NSSCKFWSession *fwSession,
161  CK_BBOOL rw,
162  CK_RV *pError
163)
164{
165  return nss_ckcapi_CreateSession(fwSession, pError);
166}
167
168static CK_ULONG
169ckcapi_mdToken_GetMechanismCount
170(
171  NSSCKMDToken *mdToken,
172  NSSCKFWToken *fwToken,
173  NSSCKMDInstance *mdInstance,
174  NSSCKFWInstance *fwInstance
175)
176{
177  return (CK_ULONG)1;
178}
179
180static CK_RV
181ckcapi_mdToken_GetMechanismTypes
182(
183  NSSCKMDToken *mdToken,
184  NSSCKFWToken *fwToken,
185  NSSCKMDInstance *mdInstance,
186  NSSCKFWInstance *fwInstance,
187  CK_MECHANISM_TYPE types[]
188)
189{
190  types[0] = CKM_RSA_PKCS;
191  return CKR_OK;
192}
193
194static NSSCKMDMechanism *
195ckcapi_mdToken_GetMechanism
196(
197  NSSCKMDToken *mdToken,
198  NSSCKFWToken *fwToken,
199  NSSCKMDInstance *mdInstance,
200  NSSCKFWInstance *fwInstance,
201  CK_MECHANISM_TYPE which,
202  CK_RV *pError
203)
204{
205  if (which != CKM_RSA_PKCS) {
206    *pError = CKR_MECHANISM_INVALID;
207    return (NSSCKMDMechanism *)NULL;
208  }
209  return (NSSCKMDMechanism *)&nss_ckcapi_mdMechanismRSA;
210}
211
212NSS_IMPLEMENT_DATA const NSSCKMDToken
213nss_ckcapi_mdToken = {
214  (void *)NULL, /* etc */
215  NULL, /* Setup */
216  NULL, /* Invalidate */
217  NULL, /* InitToken -- default errs */
218  ckcapi_mdToken_GetLabel,
219  ckcapi_mdToken_GetManufacturerID,
220  ckcapi_mdToken_GetModel,
221  ckcapi_mdToken_GetSerialNumber,
222  NULL, /* GetHasRNG -- default is false */
223  ckcapi_mdToken_GetIsWriteProtected,
224  NULL, /* GetLoginRequired -- default is false */
225  ckcapi_mdToken_GetUserPinInitialized,
226  NULL, /* GetRestoreKeyNotNeeded -- irrelevant */
227  NULL, /* GetHasClockOnToken -- default is false */
228  NULL, /* GetHasProtectedAuthenticationPath -- default is false */
229  NULL, /* GetSupportsDualCryptoOperations -- default is false */
230  NULL, /* GetMaxSessionCount -- default is CK_UNAVAILABLE_INFORMATION */
231  NULL, /* GetMaxRwSessionCount -- default is CK_UNAVAILABLE_INFORMATION */
232  NULL, /* GetMaxPinLen -- irrelevant */
233  NULL, /* GetMinPinLen -- irrelevant */
234  NULL, /* GetTotalPublicMemory -- default is CK_UNAVAILABLE_INFORMATION */
235  NULL, /* GetFreePublicMemory -- default is CK_UNAVAILABLE_INFORMATION */
236  NULL, /* GetTotalPrivateMemory -- default is CK_UNAVAILABLE_INFORMATION */
237  NULL, /* GetFreePrivateMemory -- default is CK_UNAVAILABLE_INFORMATION */
238  ckcapi_mdToken_GetHardwareVersion,
239  ckcapi_mdToken_GetFirmwareVersion,
240  NULL, /* GetUTCTime -- no clock */
241  ckcapi_mdToken_OpenSession,
242  ckcapi_mdToken_GetMechanismCount,
243  ckcapi_mdToken_GetMechanismTypes,
244  ckcapi_mdToken_GetMechanism,
245  (void *)NULL /* null terminator */
246};