Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / lib / ckfw / capi / ctoken.c
blobdb4137cddd7c9e402617f77c34a784e217c3c7a0
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
14 * The Original Code is the Netscape security libraries.
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
22 * Contributor(s):
23 * Bob Relyea (rrelyea@redhat.com)
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.
37 * ***** END LICENSE BLOCK ***** */
39 #ifdef DEBUG
40 static const char CVS_ID[] = "@(#) $RCSfile: ctoken.c,v $ $Revision: 1.2 $ $Date: 2005/11/15 00:13:58 $";
41 #endif /* DEBUG */
43 #include "ckcapi.h"
46 * ckcapi/ctoken.c
48 * This file implements the NSSCKMDToken object for the
49 * "nss to capi" cryptoki module.
52 static NSSUTF8 *
53 ckcapi_mdToken_GetLabel
55 NSSCKMDToken *mdToken,
56 NSSCKFWToken *fwToken,
57 NSSCKMDInstance *mdInstance,
58 NSSCKFWInstance *fwInstance,
59 CK_RV *pError
62 return (NSSUTF8 *)nss_ckcapi_TokenLabel;
65 static NSSUTF8 *
66 ckcapi_mdToken_GetManufacturerID
68 NSSCKMDToken *mdToken,
69 NSSCKFWToken *fwToken,
70 NSSCKMDInstance *mdInstance,
71 NSSCKFWInstance *fwInstance,
72 CK_RV *pError
75 return (NSSUTF8 *)nss_ckcapi_ManufacturerID;
78 static NSSUTF8 *
79 ckcapi_mdToken_GetModel
81 NSSCKMDToken *mdToken,
82 NSSCKFWToken *fwToken,
83 NSSCKMDInstance *mdInstance,
84 NSSCKFWInstance *fwInstance,
85 CK_RV *pError
88 return (NSSUTF8 *)nss_ckcapi_TokenModel;
91 static NSSUTF8 *
92 ckcapi_mdToken_GetSerialNumber
94 NSSCKMDToken *mdToken,
95 NSSCKFWToken *fwToken,
96 NSSCKMDInstance *mdInstance,
97 NSSCKFWInstance *fwInstance,
98 CK_RV *pError
101 return (NSSUTF8 *)nss_ckcapi_TokenSerialNumber;
104 static CK_BBOOL
105 ckcapi_mdToken_GetIsWriteProtected
107 NSSCKMDToken *mdToken,
108 NSSCKFWToken *fwToken,
109 NSSCKMDInstance *mdInstance,
110 NSSCKFWInstance *fwInstance
113 return CK_FALSE;
116 /* fake out Mozilla so we don't try to initialize the token */
117 static CK_BBOOL
118 ckcapi_mdToken_GetUserPinInitialized
120 NSSCKMDToken *mdToken,
121 NSSCKFWToken *fwToken,
122 NSSCKMDInstance *mdInstance,
123 NSSCKFWInstance *fwInstance
126 return CK_TRUE;
129 static CK_VERSION
130 ckcapi_mdToken_GetHardwareVersion
132 NSSCKMDToken *mdToken,
133 NSSCKFWToken *fwToken,
134 NSSCKMDInstance *mdInstance,
135 NSSCKFWInstance *fwInstance
138 return nss_ckcapi_HardwareVersion;
141 static CK_VERSION
142 ckcapi_mdToken_GetFirmwareVersion
144 NSSCKMDToken *mdToken,
145 NSSCKFWToken *fwToken,
146 NSSCKMDInstance *mdInstance,
147 NSSCKFWInstance *fwInstance
150 return nss_ckcapi_FirmwareVersion;
153 static NSSCKMDSession *
154 ckcapi_mdToken_OpenSession
156 NSSCKMDToken *mdToken,
157 NSSCKFWToken *fwToken,
158 NSSCKMDInstance *mdInstance,
159 NSSCKFWInstance *fwInstance,
160 NSSCKFWSession *fwSession,
161 CK_BBOOL rw,
162 CK_RV *pError
165 return nss_ckcapi_CreateSession(fwSession, pError);
168 static CK_ULONG
169 ckcapi_mdToken_GetMechanismCount
171 NSSCKMDToken *mdToken,
172 NSSCKFWToken *fwToken,
173 NSSCKMDInstance *mdInstance,
174 NSSCKFWInstance *fwInstance
177 return (CK_ULONG)1;
180 static CK_RV
181 ckcapi_mdToken_GetMechanismTypes
183 NSSCKMDToken *mdToken,
184 NSSCKFWToken *fwToken,
185 NSSCKMDInstance *mdInstance,
186 NSSCKFWInstance *fwInstance,
187 CK_MECHANISM_TYPE types[]
190 types[0] = CKM_RSA_PKCS;
191 return CKR_OK;
194 static NSSCKMDMechanism *
195 ckcapi_mdToken_GetMechanism
197 NSSCKMDToken *mdToken,
198 NSSCKFWToken *fwToken,
199 NSSCKMDInstance *mdInstance,
200 NSSCKFWInstance *fwInstance,
201 CK_MECHANISM_TYPE which,
202 CK_RV *pError
205 if (which != CKM_RSA_PKCS) {
206 *pError = CKR_MECHANISM_INVALID;
207 return (NSSCKMDMechanism *)NULL;
209 return (NSSCKMDMechanism *)&nss_ckcapi_mdMechanismRSA;
212 NSS_IMPLEMENT_DATA const NSSCKMDToken
213 nss_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 */