Back to index

lightning-sunbird  0.9+nobinonly
ctoken.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  * Portions created by Red Hat, Inc, are Copyright (C) 2005
00021  *
00022  * Contributor(s):
00023  *   Bob Relyea (rrelyea@redhat.com)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifdef DEBUG
00040 static const char CVS_ID[] = "@(#) $RCSfile: ctoken.c,v $ $Revision: 1.2 $ $Date: 2005/11/15 00:13:58 $";
00041 #endif /* DEBUG */
00042 
00043 #include "ckcapi.h"
00044 
00045 /*
00046  * ckcapi/ctoken.c
00047  *
00048  * This file implements the NSSCKMDToken object for the
00049  * "nss to capi" cryptoki module.
00050  */
00051 
00052 static NSSUTF8 *
00053 ckcapi_mdToken_GetLabel
00054 (
00055   NSSCKMDToken *mdToken,
00056   NSSCKFWToken *fwToken,
00057   NSSCKMDInstance *mdInstance,
00058   NSSCKFWInstance *fwInstance,
00059   CK_RV *pError
00060 )
00061 {
00062   return (NSSUTF8 *)nss_ckcapi_TokenLabel;
00063 }
00064 
00065 static NSSUTF8 *
00066 ckcapi_mdToken_GetManufacturerID
00067 (
00068   NSSCKMDToken *mdToken,
00069   NSSCKFWToken *fwToken,
00070   NSSCKMDInstance *mdInstance,
00071   NSSCKFWInstance *fwInstance,
00072   CK_RV *pError
00073 )
00074 {
00075   return (NSSUTF8 *)nss_ckcapi_ManufacturerID;
00076 }
00077 
00078 static NSSUTF8 *
00079 ckcapi_mdToken_GetModel
00080 (
00081   NSSCKMDToken *mdToken,
00082   NSSCKFWToken *fwToken,
00083   NSSCKMDInstance *mdInstance,
00084   NSSCKFWInstance *fwInstance,
00085   CK_RV *pError
00086 )
00087 {
00088   return (NSSUTF8 *)nss_ckcapi_TokenModel;
00089 }
00090 
00091 static NSSUTF8 *
00092 ckcapi_mdToken_GetSerialNumber
00093 (
00094   NSSCKMDToken *mdToken,
00095   NSSCKFWToken *fwToken,
00096   NSSCKMDInstance *mdInstance,
00097   NSSCKFWInstance *fwInstance,
00098   CK_RV *pError
00099 )
00100 {
00101   return (NSSUTF8 *)nss_ckcapi_TokenSerialNumber;
00102 }
00103 
00104 static CK_BBOOL
00105 ckcapi_mdToken_GetIsWriteProtected
00106 (
00107   NSSCKMDToken *mdToken,
00108   NSSCKFWToken *fwToken,
00109   NSSCKMDInstance *mdInstance,
00110   NSSCKFWInstance *fwInstance
00111 )
00112 {
00113   return CK_FALSE;
00114 }
00115 
00116 /* fake out Mozilla so we don't try to initialize the token */
00117 static CK_BBOOL
00118 ckcapi_mdToken_GetUserPinInitialized
00119 (
00120   NSSCKMDToken *mdToken,
00121   NSSCKFWToken *fwToken,
00122   NSSCKMDInstance *mdInstance,
00123   NSSCKFWInstance *fwInstance
00124 )
00125 {
00126   return CK_TRUE;
00127 }
00128 
00129 static CK_VERSION
00130 ckcapi_mdToken_GetHardwareVersion
00131 (
00132   NSSCKMDToken *mdToken,
00133   NSSCKFWToken *fwToken,
00134   NSSCKMDInstance *mdInstance,
00135   NSSCKFWInstance *fwInstance
00136 )
00137 {
00138   return nss_ckcapi_HardwareVersion;
00139 }
00140 
00141 static CK_VERSION
00142 ckcapi_mdToken_GetFirmwareVersion
00143 (
00144   NSSCKMDToken *mdToken,
00145   NSSCKFWToken *fwToken,
00146   NSSCKMDInstance *mdInstance,
00147   NSSCKFWInstance *fwInstance
00148 )
00149 {
00150   return nss_ckcapi_FirmwareVersion;
00151 }
00152 
00153 static NSSCKMDSession *
00154 ckcapi_mdToken_OpenSession
00155 (
00156   NSSCKMDToken *mdToken,
00157   NSSCKFWToken *fwToken,
00158   NSSCKMDInstance *mdInstance,
00159   NSSCKFWInstance *fwInstance,
00160   NSSCKFWSession *fwSession,
00161   CK_BBOOL rw,
00162   CK_RV *pError
00163 )
00164 {
00165   return nss_ckcapi_CreateSession(fwSession, pError);
00166 }
00167 
00168 static CK_ULONG
00169 ckcapi_mdToken_GetMechanismCount
00170 (
00171   NSSCKMDToken *mdToken,
00172   NSSCKFWToken *fwToken,
00173   NSSCKMDInstance *mdInstance,
00174   NSSCKFWInstance *fwInstance
00175 )
00176 {
00177   return (CK_ULONG)1;
00178 }
00179 
00180 static CK_RV
00181 ckcapi_mdToken_GetMechanismTypes
00182 (
00183   NSSCKMDToken *mdToken,
00184   NSSCKFWToken *fwToken,
00185   NSSCKMDInstance *mdInstance,
00186   NSSCKFWInstance *fwInstance,
00187   CK_MECHANISM_TYPE types[]
00188 )
00189 {
00190   types[0] = CKM_RSA_PKCS;
00191   return CKR_OK;
00192 }
00193 
00194 static NSSCKMDMechanism *
00195 ckcapi_mdToken_GetMechanism
00196 (
00197   NSSCKMDToken *mdToken,
00198   NSSCKFWToken *fwToken,
00199   NSSCKMDInstance *mdInstance,
00200   NSSCKFWInstance *fwInstance,
00201   CK_MECHANISM_TYPE which,
00202   CK_RV *pError
00203 )
00204 {
00205   if (which != CKM_RSA_PKCS) {
00206     *pError = CKR_MECHANISM_INVALID;
00207     return (NSSCKMDMechanism *)NULL;
00208   }
00209   return (NSSCKMDMechanism *)&nss_ckcapi_mdMechanismRSA;
00210 }
00211 
00212 NSS_IMPLEMENT_DATA const NSSCKMDToken
00213 nss_ckcapi_mdToken = {
00214   (void *)NULL, /* etc */
00215   NULL, /* Setup */
00216   NULL, /* Invalidate */
00217   NULL, /* InitToken -- default errs */
00218   ckcapi_mdToken_GetLabel,
00219   ckcapi_mdToken_GetManufacturerID,
00220   ckcapi_mdToken_GetModel,
00221   ckcapi_mdToken_GetSerialNumber,
00222   NULL, /* GetHasRNG -- default is false */
00223   ckcapi_mdToken_GetIsWriteProtected,
00224   NULL, /* GetLoginRequired -- default is false */
00225   ckcapi_mdToken_GetUserPinInitialized,
00226   NULL, /* GetRestoreKeyNotNeeded -- irrelevant */
00227   NULL, /* GetHasClockOnToken -- default is false */
00228   NULL, /* GetHasProtectedAuthenticationPath -- default is false */
00229   NULL, /* GetSupportsDualCryptoOperations -- default is false */
00230   NULL, /* GetMaxSessionCount -- default is CK_UNAVAILABLE_INFORMATION */
00231   NULL, /* GetMaxRwSessionCount -- default is CK_UNAVAILABLE_INFORMATION */
00232   NULL, /* GetMaxPinLen -- irrelevant */
00233   NULL, /* GetMinPinLen -- irrelevant */
00234   NULL, /* GetTotalPublicMemory -- default is CK_UNAVAILABLE_INFORMATION */
00235   NULL, /* GetFreePublicMemory -- default is CK_UNAVAILABLE_INFORMATION */
00236   NULL, /* GetTotalPrivateMemory -- default is CK_UNAVAILABLE_INFORMATION */
00237   NULL, /* GetFreePrivateMemory -- default is CK_UNAVAILABLE_INFORMATION */
00238   ckcapi_mdToken_GetHardwareVersion,
00239   ckcapi_mdToken_GetFirmwareVersion,
00240   NULL, /* GetUTCTime -- no clock */
00241   ckcapi_mdToken_OpenSession,
00242   ckcapi_mdToken_GetMechanismCount,
00243   ckcapi_mdToken_GetMechanismTypes,
00244   ckcapi_mdToken_GetMechanism,
00245   (void *)NULL /* null terminator */
00246 };