| 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 |
* |
| 21 |
* Contributor(s): |
| 22 |
* Rob Crittenden ([email protected]) |
| 23 |
* |
| 24 |
* Alternatively, the contents of this file may be used under the terms of |
| 25 |
* either the GNU General Public License Version 2 or later (the "GPL"), or |
| 26 |
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| 27 |
* in which case the provisions of the GPL or the LGPL are applicable instead |
| 28 |
* of those above. If you wish to allow use of your version of this file only |
| 29 |
* under the terms of either the GPL or the LGPL, and not to allow others to |
| 30 |
* use your version of this file under the terms of the MPL, indicate your |
| 31 |
* decision by deleting the provisions above and replace them with the notice |
| 32 |
* and other provisions required by the GPL or the LGPL. If you do not delete |
| 33 |
* the provisions above, a recipient may use your version of this file under |
| 34 |
* the terms of any one of the MPL, the GPL or the LGPL. |
| 35 |
* |
| 36 |
* ***** END LICENSE BLOCK ***** */ |
| 37 |
|
| 38 |
#include "ckpem.h" |
| 39 |
|
| 40 |
/* |
| 41 |
* pslot.c |
| 42 |
* |
| 43 |
* This file implements the NSSCKMDSlot object for the |
| 44 |
* "PEM objects" cryptoki module. |
| 45 |
*/ |
| 46 |
|
| 47 |
static NSSUTF8 * |
| 48 |
pem_mdSlot_GetSlotDescription |
| 49 |
( |
| 50 |
NSSCKMDSlot * mdSlot, |
| 51 |
NSSCKFWSlot * fwSlot, |
| 52 |
NSSCKMDInstance * mdInstance, |
| 53 |
NSSCKFWInstance * fwInstance, |
| 54 |
CK_RV * pError |
| 55 |
) |
| 56 |
{ |
| 57 |
CK_SLOT_ID slotID; |
| 58 |
NSSArena *arena; |
| 59 |
char *slotid; |
| 60 |
|
| 61 |
arena = NSSCKFWInstance_GetArena(fwInstance, pError); |
| 62 |
slotID = NSSCKFWSlot_GetSlotID(fwSlot); |
| 63 |
|
| 64 |
slotid = (char *) NSS_ZAlloc(arena, 256); |
| 65 |
snprintf(slotid, 256, "PEM Slot #%ld", slotID); |
| 66 |
|
| 67 |
return (NSSUTF8 *) slotid; |
| 68 |
} |
| 69 |
|
| 70 |
static NSSUTF8 * |
| 71 |
pem_mdSlot_GetManufacturerID |
| 72 |
( |
| 73 |
NSSCKMDSlot * mdSlot, |
| 74 |
NSSCKFWSlot * fwSlot, |
| 75 |
NSSCKMDInstance * mdInstance, |
| 76 |
NSSCKFWInstance * fwInstance, |
| 77 |
CK_RV * pError |
| 78 |
) |
| 79 |
{ |
| 80 |
return (NSSUTF8 *) pem_ManufacturerID; |
| 81 |
} |
| 82 |
|
| 83 |
static CK_VERSION |
| 84 |
pem_mdSlot_GetHardwareVersion |
| 85 |
( |
| 86 |
NSSCKMDSlot * mdSlot, |
| 87 |
NSSCKFWSlot * fwSlot, |
| 88 |
NSSCKMDInstance * mdInstance, |
| 89 |
NSSCKFWInstance * fwInstance |
| 90 |
) |
| 91 |
{ |
| 92 |
return pem_HardwareVersion; |
| 93 |
} |
| 94 |
|
| 95 |
static CK_VERSION |
| 96 |
pem_mdSlot_GetFirmwareVersion |
| 97 |
( |
| 98 |
NSSCKMDSlot * mdSlot, |
| 99 |
NSSCKFWSlot * fwSlot, |
| 100 |
NSSCKMDInstance * mdInstance, |
| 101 |
NSSCKFWInstance * fwInstance |
| 102 |
) |
| 103 |
{ |
| 104 |
return pem_FirmwareVersion; |
| 105 |
} |
| 106 |
|
| 107 |
static NSSCKMDToken * |
| 108 |
pem_mdSlot_GetToken |
| 109 |
( |
| 110 |
NSSCKMDSlot * mdSlot, |
| 111 |
NSSCKFWSlot * fwSlot, |
| 112 |
NSSCKMDInstance * mdInstance, |
| 113 |
NSSCKFWInstance * fwInstance, |
| 114 |
CK_RV * pError |
| 115 |
) |
| 116 |
{ |
| 117 |
return (NSSCKMDToken *) mdSlot->etc; |
| 118 |
} |
| 119 |
|
| 120 |
CK_BBOOL |
| 121 |
pem_mdSlot_GetRemovableDevice |
| 122 |
( |
| 123 |
NSSCKMDSlot * mdSlot, |
| 124 |
NSSCKFWSlot * fwSlot, |
| 125 |
NSSCKMDInstance * mdInstance, |
| 126 |
NSSCKFWInstance * fwInstance |
| 127 |
) |
| 128 |
{ |
| 129 |
return CK_TRUE; |
| 130 |
} |
| 131 |
|
| 132 |
NSSCKMDSlot * |
| 133 |
pem_NewSlot |
| 134 |
( |
| 135 |
NSSCKFWInstance * fwInstance, |
| 136 |
CK_RV * pError |
| 137 |
) |
| 138 |
{ |
| 139 |
NSSArena *arena; |
| 140 |
NSSCKMDSlot *mdSlot; |
| 141 |
|
| 142 |
plog("pem_NewSlot\n"); |
| 143 |
arena = NSSCKFWInstance_GetArena(fwInstance, pError); |
| 144 |
if ((NSSArena *) NULL == arena) { |
| 145 |
if (CKR_OK == *pError) { |
| 146 |
*pError = CKR_GENERAL_ERROR; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
mdSlot = NSS_ZNEW(arena, NSSCKMDSlot); |
| 151 |
if ((NSSCKMDSlot *) NULL == mdSlot) { |
| 152 |
*pError = CKR_HOST_MEMORY; |
| 153 |
return (NSSCKMDSlot *) NULL; |
| 154 |
} |
| 155 |
|
| 156 |
mdSlot->etc = pem_NewToken(fwInstance, pError); |
| 157 |
|
| 158 |
mdSlot->GetSlotDescription = pem_mdSlot_GetSlotDescription; |
| 159 |
mdSlot->GetManufacturerID = pem_mdSlot_GetManufacturerID; |
| 160 |
mdSlot->GetHardwareVersion = pem_mdSlot_GetHardwareVersion; |
| 161 |
mdSlot->GetFirmwareVersion = pem_mdSlot_GetFirmwareVersion; |
| 162 |
mdSlot->GetRemovableDevice = pem_mdSlot_GetRemovableDevice; |
| 163 |
mdSlot->GetToken = pem_mdSlot_GetToken; |
| 164 |
|
| 165 |
return mdSlot; |
| 166 |
} |
| 167 |
|
| 168 |
NSS_IMPLEMENT_DATA const NSSCKMDSlot |
| 169 |
pem_mdSlot = { |
| 170 |
(void *) NULL, /* etc */ |
| 171 |
NULL, /* Initialize */ |
| 172 |
NULL, /* Destroy */ |
| 173 |
pem_mdSlot_GetSlotDescription, |
| 174 |
pem_mdSlot_GetManufacturerID, |
| 175 |
NULL, /* GetTokenPresent -- defaults to true */ |
| 176 |
pem_mdSlot_GetRemovableDevice, |
| 177 |
NULL, /* GetHardwareSlot -- defaults to false */ |
| 178 |
pem_mdSlot_GetHardwareVersion, |
| 179 |
pem_mdSlot_GetFirmwareVersion, |
| 180 |
pem_mdSlot_GetToken, |
| 181 |
(void *) NULL /* null terminator */ |
| 182 |
}; |