| 1 |
/* |
| 2 |
* Copyright (c)2010 SURFnet bv |
| 3 |
* All rights reserved. |
| 4 |
* |
| 5 |
* Redistribution and use in source and binary forms, with or without |
| 6 |
* modification, are permitted provided that the following conditions |
| 7 |
* are met: |
| 8 |
* 1. Redistributions of source code must retain the above copyright |
| 9 |
* notice, this list of conditions and the following disclaimer. |
| 10 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 11 |
* notice, this list of conditions and the following disclaimer in the |
| 12 |
* documentation and/or other materials provided with the distribution. |
| 13 |
* |
| 14 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 15 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 18 |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 20 |
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 21 |
* INTERRUPTION)HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 22 |
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 23 |
* OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 24 |
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 |
*/ |
| 26 |
|
| 27 |
/***************************************************************************** |
| 28 |
main.cpp |
| 29 |
|
| 30 |
This file contains the main entry point to the PKCS #11 library. All it does |
| 31 |
is dispatch calls to the actual implementation and check for fatal exceptions |
| 32 |
on the boundary of the library. |
| 33 |
*****************************************************************************/ |
| 34 |
|
| 35 |
// The functions are exported library/DLL entry points |
| 36 |
#define CRYPTOKI_EXPORTS |
| 37 |
|
| 38 |
#include "config.h" |
| 39 |
#include "log.h" |
| 40 |
#include "fatal.h" |
| 41 |
#include "cryptoki.h" |
| 42 |
#include "SoftHSM.h" |
| 43 |
|
| 44 |
#if defined(__GNUC__) && \ |
| 45 |
(__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) || \ |
| 46 |
defined(__SUNPRO_C) && __SUNPRO_C >= 0x590 |
| 47 |
#define PKCS_API __attribute__ ((visibility("default"))) |
| 48 |
#else |
| 49 |
#define PKCS_API |
| 50 |
#endif |
| 51 |
|
| 52 |
// PKCS #11 function list |
| 53 |
static CK_FUNCTION_LIST functionList = |
| 54 |
{ |
| 55 |
// Version information |
| 56 |
{ CRYPTOKI_VERSION_MAJOR, CRYPTOKI_VERSION_MINOR }, |
| 57 |
// Function pointers |
| 58 |
C_Initialize, |
| 59 |
C_Finalize, |
| 60 |
C_GetInfo, |
| 61 |
C_GetFunctionList, |
| 62 |
C_GetSlotList, |
| 63 |
C_GetSlotInfo, |
| 64 |
C_GetTokenInfo, |
| 65 |
C_GetMechanismList, |
| 66 |
C_GetMechanismInfo, |
| 67 |
C_InitToken, |
| 68 |
C_InitPIN, |
| 69 |
C_SetPIN, |
| 70 |
C_OpenSession, |
| 71 |
C_CloseSession, |
| 72 |
C_CloseAllSessions, |
| 73 |
C_GetSessionInfo, |
| 74 |
C_GetOperationState, |
| 75 |
C_SetOperationState, |
| 76 |
C_Login, |
| 77 |
C_Logout, |
| 78 |
C_CreateObject, |
| 79 |
C_CopyObject, |
| 80 |
C_DestroyObject, |
| 81 |
C_GetObjectSize, |
| 82 |
C_GetAttributeValue, |
| 83 |
C_SetAttributeValue, |
| 84 |
C_FindObjectsInit, |
| 85 |
C_FindObjects, |
| 86 |
C_FindObjectsFinal, |
| 87 |
C_EncryptInit, |
| 88 |
C_Encrypt, |
| 89 |
C_EncryptUpdate, |
| 90 |
C_EncryptFinal, |
| 91 |
C_DecryptInit, |
| 92 |
C_Decrypt, |
| 93 |
C_DecryptUpdate, |
| 94 |
C_DecryptFinal, |
| 95 |
C_DigestInit, |
| 96 |
C_Digest, |
| 97 |
C_DigestUpdate, |
| 98 |
C_DigestKey, |
| 99 |
C_DigestFinal, |
| 100 |
C_SignInit, |
| 101 |
C_Sign, |
| 102 |
C_SignUpdate, |
| 103 |
C_SignFinal, |
| 104 |
C_SignRecoverInit, |
| 105 |
C_SignRecover, |
| 106 |
C_VerifyInit, |
| 107 |
C_Verify, |
| 108 |
C_VerifyUpdate, |
| 109 |
C_VerifyFinal, |
| 110 |
C_VerifyRecoverInit, |
| 111 |
C_VerifyRecover, |
| 112 |
C_DigestEncryptUpdate, |
| 113 |
C_DecryptDigestUpdate, |
| 114 |
C_SignEncryptUpdate, |
| 115 |
C_DecryptVerifyUpdate, |
| 116 |
C_GenerateKey, |
| 117 |
C_GenerateKeyPair, |
| 118 |
C_WrapKey, |
| 119 |
C_UnwrapKey, |
| 120 |
C_DeriveKey, |
| 121 |
C_SeedRandom, |
| 122 |
C_GenerateRandom, |
| 123 |
C_GetFunctionStatus, |
| 124 |
C_CancelFunction, |
| 125 |
C_WaitForSlotEvent |
| 126 |
}; |
| 127 |
|
| 128 |
// PKCS #11 initialisation function |
| 129 |
PKCS_API CK_RV C_Initialize(CK_VOID_PTR pInitArgs) |
| 130 |
{ |
| 131 |
try |
| 132 |
{ |
| 133 |
return SoftHSM::i()->C_Initialize(pInitArgs); |
| 134 |
} |
| 135 |
catch (...) |
| 136 |
{ |
| 137 |
FatalException(); |
| 138 |
} |
| 139 |
|
| 140 |
return CKR_FUNCTION_FAILED; |
| 141 |
} |
| 142 |
|
| 143 |
// PKCS #11 finalisation function |
| 144 |
PKCS_API CK_RV C_Finalize(CK_VOID_PTR pReserved) |
| 145 |
{ |
| 146 |
try |
| 147 |
{ |
| 148 |
return SoftHSM::i()->C_Finalize(pReserved); |
| 149 |
} |
| 150 |
catch (...) |
| 151 |
{ |
| 152 |
FatalException(); |
| 153 |
} |
| 154 |
|
| 155 |
return CKR_FUNCTION_FAILED; |
| 156 |
} |
| 157 |
|
| 158 |
// Return information about the PKCS #11 module |
| 159 |
PKCS_API CK_RV C_GetInfo(CK_INFO_PTR pInfo) |
| 160 |
{ |
| 161 |
try |
| 162 |
{ |
| 163 |
return SoftHSM::i()->C_GetInfo(pInfo); |
| 164 |
} |
| 165 |
catch (...) |
| 166 |
{ |
| 167 |
FatalException(); |
| 168 |
} |
| 169 |
|
| 170 |
return CKR_FUNCTION_FAILED; |
| 171 |
} |
| 172 |
|
| 173 |
// Return the list of PKCS #11 functions |
| 174 |
PKCS_API CK_RV C_GetFunctionList(CK_FUNCTION_LIST_PTR_PTR ppFunctionList) |
| 175 |
{ |
| 176 |
try |
| 177 |
{ |
| 178 |
if (ppFunctionList == NULL_PTR) return CKR_ARGUMENTS_BAD; |
| 179 |
|
| 180 |
*ppFunctionList = &functionList; |
| 181 |
|
| 182 |
return CKR_OK; |
| 183 |
} |
| 184 |
catch (...) |
| 185 |
{ |
| 186 |
FatalException(); |
| 187 |
} |
| 188 |
|
| 189 |
return CKR_FUNCTION_FAILED; |
| 190 |
} |
| 191 |
|
| 192 |
// Return a list of available slots |
| 193 |
PKCS_API CK_RV C_GetSlotList(CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList, CK_ULONG_PTR pulCount) |
| 194 |
{ |
| 195 |
try |
| 196 |
{ |
| 197 |
return SoftHSM::i()->C_GetSlotList(tokenPresent, pSlotList, pulCount); |
| 198 |
} |
| 199 |
catch (...) |
| 200 |
{ |
| 201 |
FatalException(); |
| 202 |
} |
| 203 |
|
| 204 |
return CKR_FUNCTION_FAILED; |
| 205 |
} |
| 206 |
|
| 207 |
// Return information about a slot |
| 208 |
PKCS_API CK_RV C_GetSlotInfo(CK_SLOT_ID slotID, CK_SLOT_INFO_PTR pInfo) |
| 209 |
{ |
| 210 |
try |
| 211 |
{ |
| 212 |
return SoftHSM::i()->C_GetSlotInfo(slotID, pInfo); |
| 213 |
} |
| 214 |
catch (...) |
| 215 |
{ |
| 216 |
FatalException(); |
| 217 |
} |
| 218 |
|
| 219 |
return CKR_FUNCTION_FAILED; |
| 220 |
} |
| 221 |
|
| 222 |
// Return information about a token in a slot |
| 223 |
PKCS_API CK_RV C_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo) |
| 224 |
{ |
| 225 |
try |
| 226 |
{ |
| 227 |
return SoftHSM::i()->C_GetTokenInfo(slotID, pInfo); |
| 228 |
} |
| 229 |
catch (...) |
| 230 |
{ |
| 231 |
FatalException(); |
| 232 |
} |
| 233 |
|
| 234 |
return CKR_FUNCTION_FAILED; |
| 235 |
} |
| 236 |
|
| 237 |
// Return the list of supported mechanisms for a given slot |
| 238 |
PKCS_API CK_RV C_GetMechanismList(CK_SLOT_ID slotID, CK_MECHANISM_TYPE_PTR pMechanismList, CK_ULONG_PTR pulCount) |
| 239 |
{ |
| 240 |
try |
| 241 |
{ |
| 242 |
return SoftHSM::i()->C_GetMechanismList(slotID, pMechanismList, pulCount); |
| 243 |
} |
| 244 |
catch (...) |
| 245 |
{ |
| 246 |
FatalException(); |
| 247 |
} |
| 248 |
|
| 249 |
return CKR_FUNCTION_FAILED; |
| 250 |
} |
| 251 |
|
| 252 |
// Return more information about a mechanism for a given slot |
| 253 |
PKCS_API CK_RV C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, CK_MECHANISM_INFO_PTR pInfo) |
| 254 |
{ |
| 255 |
try |
| 256 |
{ |
| 257 |
return SoftHSM::i()->C_GetMechanismInfo(slotID, type, pInfo); |
| 258 |
} |
| 259 |
catch (...) |
| 260 |
{ |
| 261 |
FatalException(); |
| 262 |
} |
| 263 |
|
| 264 |
return CKR_FUNCTION_FAILED; |
| 265 |
} |
| 266 |
|
| 267 |
// Initialise the token in the specified slot |
| 268 |
PKCS_API CK_RV C_InitToken(CK_SLOT_ID slotID, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen, CK_UTF8CHAR_PTR pLabel) |
| 269 |
{ |
| 270 |
try |
| 271 |
{ |
| 272 |
return SoftHSM::i()->C_InitToken(slotID, pPin, ulPinLen, pLabel); |
| 273 |
} |
| 274 |
catch (...) |
| 275 |
{ |
| 276 |
FatalException(); |
| 277 |
} |
| 278 |
|
| 279 |
return CKR_FUNCTION_FAILED; |
| 280 |
} |
| 281 |
|
| 282 |
// Initialise the user PIN |
| 283 |
PKCS_API CK_RV C_InitPIN(CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen) |
| 284 |
{ |
| 285 |
try |
| 286 |
{ |
| 287 |
return SoftHSM::i()->C_InitPIN(hSession, pPin, ulPinLen); |
| 288 |
} |
| 289 |
catch (...) |
| 290 |
{ |
| 291 |
FatalException(); |
| 292 |
} |
| 293 |
|
| 294 |
return CKR_FUNCTION_FAILED; |
| 295 |
} |
| 296 |
|
| 297 |
// Change the PIN |
| 298 |
PKCS_API CK_RV C_SetPIN(CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pOldPin, CK_ULONG ulOldLen, CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewLen) |
| 299 |
{ |
| 300 |
try |
| 301 |
{ |
| 302 |
return SoftHSM::i()->C_SetPIN(hSession, pOldPin, ulOldLen, pNewPin, ulNewLen); |
| 303 |
} |
| 304 |
catch (...) |
| 305 |
{ |
| 306 |
FatalException(); |
| 307 |
} |
| 308 |
|
| 309 |
return CKR_FUNCTION_FAILED; |
| 310 |
} |
| 311 |
|
| 312 |
// Open a new session to the specified slot |
| 313 |
PKCS_API CK_RV C_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, CK_VOID_PTR pApplication, CK_NOTIFY notify, CK_SESSION_HANDLE_PTR phSession) |
| 314 |
{ |
| 315 |
try |
| 316 |
{ |
| 317 |
return SoftHSM::i()->C_OpenSession(slotID, flags, pApplication, notify, phSession); |
| 318 |
} |
| 319 |
catch (...) |
| 320 |
{ |
| 321 |
FatalException(); |
| 322 |
} |
| 323 |
|
| 324 |
return CKR_FUNCTION_FAILED; |
| 325 |
} |
| 326 |
|
| 327 |
// Close the given session |
| 328 |
PKCS_API CK_RV C_CloseSession(CK_SESSION_HANDLE hSession) |
| 329 |
{ |
| 330 |
try |
| 331 |
{ |
| 332 |
return SoftHSM::i()->C_CloseSession(hSession); |
| 333 |
} |
| 334 |
catch (...) |
| 335 |
{ |
| 336 |
FatalException(); |
| 337 |
} |
| 338 |
|
| 339 |
return CKR_FUNCTION_FAILED; |
| 340 |
} |
| 341 |
|
| 342 |
// Close all open sessions |
| 343 |
PKCS_API CK_RV C_CloseAllSessions(CK_SLOT_ID slotID) |
| 344 |
{ |
| 345 |
try |
| 346 |
{ |
| 347 |
return SoftHSM::i()->C_CloseAllSessions(slotID); |
| 348 |
} |
| 349 |
catch (...) |
| 350 |
{ |
| 351 |
FatalException(); |
| 352 |
} |
| 353 |
|
| 354 |
return CKR_FUNCTION_FAILED; |
| 355 |
} |
| 356 |
|
| 357 |
// Retrieve information about the specified session |
| 358 |
PKCS_API CK_RV C_GetSessionInfo(CK_SESSION_HANDLE hSession, CK_SESSION_INFO_PTR pInfo) |
| 359 |
{ |
| 360 |
try |
| 361 |
{ |
| 362 |
return SoftHSM::i()->C_GetSessionInfo(hSession, pInfo); |
| 363 |
} |
| 364 |
catch (...) |
| 365 |
{ |
| 366 |
FatalException(); |
| 367 |
} |
| 368 |
|
| 369 |
return CKR_FUNCTION_FAILED; |
| 370 |
} |
| 371 |
|
| 372 |
// Determine the state of a running operation in a session |
| 373 |
PKCS_API CK_RV C_GetOperationState(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pOperationState, CK_ULONG_PTR pulOperationStateLen) |
| 374 |
{ |
| 375 |
try |
| 376 |
{ |
| 377 |
return SoftHSM::i()->C_GetOperationState(hSession, pOperationState, pulOperationStateLen); |
| 378 |
} |
| 379 |
catch (...) |
| 380 |
{ |
| 381 |
FatalException(); |
| 382 |
} |
| 383 |
|
| 384 |
return CKR_FUNCTION_FAILED; |
| 385 |
} |
| 386 |
|
| 387 |
// Set the operation sate in a session |
| 388 |
PKCS_API CK_RV C_SetOperationState(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pOperationState, CK_ULONG ulOperationStateLen, CK_OBJECT_HANDLE hEncryptionKey, CK_OBJECT_HANDLE hAuthenticationKey) |
| 389 |
{ |
| 390 |
try |
| 391 |
{ |
| 392 |
return SoftHSM::i()->C_SetOperationState(hSession, pOperationState, ulOperationStateLen, hEncryptionKey, hAuthenticationKey); |
| 393 |
} |
| 394 |
catch (...) |
| 395 |
{ |
| 396 |
FatalException(); |
| 397 |
} |
| 398 |
|
| 399 |
return CKR_FUNCTION_FAILED; |
| 400 |
} |
| 401 |
|
| 402 |
// Login on the token in the specified session |
| 403 |
PKCS_API CK_RV C_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen) |
| 404 |
{ |
| 405 |
try |
| 406 |
{ |
| 407 |
return SoftHSM::i()->C_Login(hSession, userType, pPin, ulPinLen); |
| 408 |
} |
| 409 |
catch (...) |
| 410 |
{ |
| 411 |
FatalException(); |
| 412 |
} |
| 413 |
|
| 414 |
return CKR_FUNCTION_FAILED; |
| 415 |
} |
| 416 |
|
| 417 |
// Log out of the token in the specified session |
| 418 |
PKCS_API CK_RV C_Logout(CK_SESSION_HANDLE hSession) |
| 419 |
{ |
| 420 |
try |
| 421 |
{ |
| 422 |
return SoftHSM::i()->C_Logout(hSession); |
| 423 |
} |
| 424 |
catch (...) |
| 425 |
{ |
| 426 |
FatalException(); |
| 427 |
} |
| 428 |
|
| 429 |
return CKR_FUNCTION_FAILED; |
| 430 |
} |
| 431 |
|
| 432 |
// Create a new object on the token in the specified session using the given attribute template |
| 433 |
PKCS_API CK_RV C_CreateObject(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, CK_OBJECT_HANDLE_PTR phObject) |
| 434 |
{ |
| 435 |
try |
| 436 |
{ |
| 437 |
return SoftHSM::i()->C_CreateObject(hSession, pTemplate, ulCount, phObject); |
| 438 |
} |
| 439 |
catch (...) |
| 440 |
{ |
| 441 |
FatalException(); |
| 442 |
} |
| 443 |
|
| 444 |
return CKR_FUNCTION_FAILED; |
| 445 |
} |
| 446 |
|
| 447 |
// Create a copy of the object with the specified handle |
| 448 |
PKCS_API CK_RV C_CopyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, CK_OBJECT_HANDLE_PTR phNewObject) |
| 449 |
{ |
| 450 |
try |
| 451 |
{ |
| 452 |
return SoftHSM::i()->C_CopyObject(hSession, hObject, pTemplate, ulCount, phNewObject); |
| 453 |
} |
| 454 |
catch (...) |
| 455 |
{ |
| 456 |
FatalException(); |
| 457 |
} |
| 458 |
|
| 459 |
return CKR_FUNCTION_FAILED; |
| 460 |
} |
| 461 |
|
| 462 |
// Destroy the specified object |
| 463 |
PKCS_API CK_RV C_DestroyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject) |
| 464 |
{ |
| 465 |
try |
| 466 |
{ |
| 467 |
return SoftHSM::i()->C_DestroyObject(hSession, hObject); |
| 468 |
} |
| 469 |
catch (...) |
| 470 |
{ |
| 471 |
FatalException(); |
| 472 |
} |
| 473 |
|
| 474 |
return CKR_FUNCTION_FAILED; |
| 475 |
} |
| 476 |
|
| 477 |
// Determine the size of the specified object |
| 478 |
PKCS_API CK_RV C_GetObjectSize(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, CK_ULONG_PTR pulSize) |
| 479 |
{ |
| 480 |
try |
| 481 |
{ |
| 482 |
return SoftHSM::i()->C_GetObjectSize(hSession, hObject, pulSize); |
| 483 |
} |
| 484 |
catch (...) |
| 485 |
{ |
| 486 |
FatalException(); |
| 487 |
} |
| 488 |
|
| 489 |
return CKR_FUNCTION_FAILED; |
| 490 |
} |
| 491 |
|
| 492 |
// Retrieve the specified attributes for the given object |
| 493 |
PKCS_API CK_RV C_GetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount) |
| 494 |
{ |
| 495 |
try |
| 496 |
{ |
| 497 |
return SoftHSM::i()->C_GetAttributeValue(hSession, hObject, pTemplate, ulCount); |
| 498 |
} |
| 499 |
catch (...) |
| 500 |
{ |
| 501 |
FatalException(); |
| 502 |
} |
| 503 |
|
| 504 |
return CKR_FUNCTION_FAILED; |
| 505 |
} |
| 506 |
|
| 507 |
// Change or set the value of the specified attributes on the specified object |
| 508 |
PKCS_API CK_RV C_SetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount) |
| 509 |
{ |
| 510 |
try |
| 511 |
{ |
| 512 |
return SoftHSM::i()->C_SetAttributeValue(hSession, hObject, pTemplate, ulCount); |
| 513 |
} |
| 514 |
catch (...) |
| 515 |
{ |
| 516 |
FatalException(); |
| 517 |
} |
| 518 |
|
| 519 |
return CKR_FUNCTION_FAILED; |
| 520 |
} |
| 521 |
|
| 522 |
// Initialise object search in the specified session using the specified attribute template as search parameters |
| 523 |
PKCS_API CK_RV C_FindObjectsInit(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount) |
| 524 |
{ |
| 525 |
try |
| 526 |
{ |
| 527 |
return SoftHSM::i()->C_FindObjectsInit(hSession, pTemplate, ulCount); |
| 528 |
} |
| 529 |
catch (...) |
| 530 |
{ |
| 531 |
FatalException(); |
| 532 |
} |
| 533 |
|
| 534 |
return CKR_FUNCTION_FAILED; |
| 535 |
} |
| 536 |
|
| 537 |
// Continue the search for objects in the specified session |
| 538 |
PKCS_API CK_RV C_FindObjects(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE_PTR phObject, CK_ULONG ulMaxObjectCount, CK_ULONG_PTR pulObjectCount) |
| 539 |
{ |
| 540 |
try |
| 541 |
{ |
| 542 |
return SoftHSM::i()->C_FindObjects(hSession, phObject, ulMaxObjectCount, pulObjectCount); |
| 543 |
} |
| 544 |
catch (...) |
| 545 |
{ |
| 546 |
FatalException(); |
| 547 |
} |
| 548 |
|
| 549 |
return CKR_FUNCTION_FAILED; |
| 550 |
} |
| 551 |
|
| 552 |
// Finish searching for objects |
| 553 |
PKCS_API CK_RV C_FindObjectsFinal(CK_SESSION_HANDLE hSession) |
| 554 |
{ |
| 555 |
try |
| 556 |
{ |
| 557 |
return SoftHSM::i()->C_FindObjectsFinal(hSession); |
| 558 |
} |
| 559 |
catch (...) |
| 560 |
{ |
| 561 |
FatalException(); |
| 562 |
} |
| 563 |
|
| 564 |
return CKR_FUNCTION_FAILED; |
| 565 |
} |
| 566 |
|
| 567 |
// Initialise encryption using the specified object and mechanism |
| 568 |
PKCS_API CK_RV C_EncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hObject) |
| 569 |
{ |
| 570 |
try |
| 571 |
{ |
| 572 |
return SoftHSM::i()->C_EncryptInit(hSession, pMechanism, hObject); |
| 573 |
} |
| 574 |
catch (...) |
| 575 |
{ |
| 576 |
FatalException(); |
| 577 |
} |
| 578 |
|
| 579 |
return CKR_FUNCTION_FAILED; |
| 580 |
} |
| 581 |
|
| 582 |
// Perform a single operation encryption operation in the specified session |
| 583 |
PKCS_API CK_RV C_Encrypt(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pEncryptedData, CK_ULONG_PTR pulEncryptedDataLen) |
| 584 |
{ |
| 585 |
try |
| 586 |
{ |
| 587 |
return SoftHSM::i()->C_Encrypt(hSession, pData, ulDataLen, pEncryptedData, pulEncryptedDataLen); |
| 588 |
} |
| 589 |
catch (...) |
| 590 |
{ |
| 591 |
FatalException(); |
| 592 |
} |
| 593 |
|
| 594 |
return CKR_FUNCTION_FAILED; |
| 595 |
} |
| 596 |
|
| 597 |
// Feed data to the running encryption operation in a session |
| 598 |
PKCS_API CK_RV C_EncryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pEncryptedData, CK_ULONG_PTR pulEncryptedDataLen) |
| 599 |
{ |
| 600 |
try |
| 601 |
{ |
| 602 |
return SoftHSM::i()->C_EncryptUpdate(hSession, pData, ulDataLen, pEncryptedData, pulEncryptedDataLen); |
| 603 |
} |
| 604 |
catch (...) |
| 605 |
{ |
| 606 |
FatalException(); |
| 607 |
} |
| 608 |
|
| 609 |
return CKR_FUNCTION_FAILED; |
| 610 |
} |
| 611 |
|
| 612 |
// Finalise the encryption operation |
| 613 |
PKCS_API CK_RV C_EncryptFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedData, CK_ULONG_PTR pulEncryptedDataLen) |
| 614 |
{ |
| 615 |
try |
| 616 |
{ |
| 617 |
return SoftHSM::i()->C_EncryptFinal(hSession, pEncryptedData, pulEncryptedDataLen); |
| 618 |
} |
| 619 |
catch (...) |
| 620 |
{ |
| 621 |
FatalException(); |
| 622 |
} |
| 623 |
|
| 624 |
return CKR_FUNCTION_FAILED; |
| 625 |
} |
| 626 |
|
| 627 |
// Initialise decryption using the specified object |
| 628 |
PKCS_API CK_RV C_DecryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hObject) |
| 629 |
{ |
| 630 |
try |
| 631 |
{ |
| 632 |
return SoftHSM::i()->C_DecryptInit(hSession, pMechanism, hObject); |
| 633 |
} |
| 634 |
catch (...) |
| 635 |
{ |
| 636 |
FatalException(); |
| 637 |
} |
| 638 |
|
| 639 |
return CKR_FUNCTION_FAILED; |
| 640 |
} |
| 641 |
|
| 642 |
// Perform a single operation decryption in the given session |
| 643 |
PKCS_API CK_RV C_Decrypt(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedData, CK_ULONG ulEncryptedDataLen, CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen) |
| 644 |
{ |
| 645 |
try |
| 646 |
{ |
| 647 |
return SoftHSM::i()->C_Decrypt(hSession, pEncryptedData, ulEncryptedDataLen, pData, pulDataLen); |
| 648 |
} |
| 649 |
catch (...) |
| 650 |
{ |
| 651 |
FatalException(); |
| 652 |
} |
| 653 |
|
| 654 |
return CKR_FUNCTION_FAILED; |
| 655 |
} |
| 656 |
|
| 657 |
// Feed data to the running decryption operation in a session |
| 658 |
PKCS_API CK_RV C_DecryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedData, CK_ULONG ulEncryptedDataLen, CK_BYTE_PTR pData, CK_ULONG_PTR pDataLen) |
| 659 |
{ |
| 660 |
try |
| 661 |
{ |
| 662 |
return SoftHSM::i()->C_DecryptUpdate(hSession, pEncryptedData, ulEncryptedDataLen, pData, pDataLen); |
| 663 |
} |
| 664 |
catch (...) |
| 665 |
{ |
| 666 |
FatalException(); |
| 667 |
} |
| 668 |
|
| 669 |
return CKR_FUNCTION_FAILED; |
| 670 |
} |
| 671 |
|
| 672 |
// Finalise the decryption operation |
| 673 |
PKCS_API CK_RV C_DecryptFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG_PTR pDataLen) |
| 674 |
{ |
| 675 |
try |
| 676 |
{ |
| 677 |
return SoftHSM::i()->C_DecryptFinal(hSession, pData, pDataLen); |
| 678 |
} |
| 679 |
catch (...) |
| 680 |
{ |
| 681 |
FatalException(); |
| 682 |
} |
| 683 |
|
| 684 |
return CKR_FUNCTION_FAILED; |
| 685 |
} |
| 686 |
|
| 687 |
// Initialise digesting using the specified mechanism in the specified session |
| 688 |
PKCS_API CK_RV C_DigestInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism) |
| 689 |
{ |
| 690 |
try |
| 691 |
{ |
| 692 |
return SoftHSM::i()->C_DigestInit(hSession, pMechanism); |
| 693 |
} |
| 694 |
catch (...) |
| 695 |
{ |
| 696 |
FatalException(); |
| 697 |
} |
| 698 |
|
| 699 |
return CKR_FUNCTION_FAILED; |
| 700 |
} |
| 701 |
|
| 702 |
// Digest the specified data in a one-pass operation and return the resulting digest |
| 703 |
PKCS_API CK_RV C_Digest(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen) |
| 704 |
{ |
| 705 |
try |
| 706 |
{ |
| 707 |
return SoftHSM::i()->C_Digest(hSession, pData, ulDataLen, pDigest, pulDigestLen); |
| 708 |
} |
| 709 |
catch (...) |
| 710 |
{ |
| 711 |
FatalException(); |
| 712 |
} |
| 713 |
|
| 714 |
return CKR_FUNCTION_FAILED; |
| 715 |
} |
| 716 |
|
| 717 |
// Update a running digest operation |
| 718 |
PKCS_API CK_RV C_DigestUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen) |
| 719 |
{ |
| 720 |
try |
| 721 |
{ |
| 722 |
return SoftHSM::i()->C_DigestUpdate(hSession, pPart, ulPartLen); |
| 723 |
} |
| 724 |
catch (...) |
| 725 |
{ |
| 726 |
FatalException(); |
| 727 |
} |
| 728 |
|
| 729 |
return CKR_FUNCTION_FAILED; |
| 730 |
} |
| 731 |
|
| 732 |
// Update a running digest operation by digesting a secret key with the specified handle |
| 733 |
PKCS_API CK_RV C_DigestKey(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject) |
| 734 |
{ |
| 735 |
try |
| 736 |
{ |
| 737 |
return SoftHSM::i()->C_DigestKey(hSession, hObject); |
| 738 |
} |
| 739 |
catch (...) |
| 740 |
{ |
| 741 |
FatalException(); |
| 742 |
} |
| 743 |
|
| 744 |
return CKR_FUNCTION_FAILED; |
| 745 |
} |
| 746 |
|
| 747 |
// Finalise the digest operation in the specified session and return the digest |
| 748 |
PKCS_API CK_RV C_DigestFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen) |
| 749 |
{ |
| 750 |
try |
| 751 |
{ |
| 752 |
return SoftHSM::i()->C_DigestFinal(hSession, pDigest, pulDigestLen); |
| 753 |
} |
| 754 |
catch (...) |
| 755 |
{ |
| 756 |
FatalException(); |
| 757 |
} |
| 758 |
|
| 759 |
return CKR_FUNCTION_FAILED; |
| 760 |
} |
| 761 |
|
| 762 |
// Initialise a signing operation using the specified key and mechanism |
| 763 |
PKCS_API CK_RV C_SignInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey) |
| 764 |
{ |
| 765 |
try |
| 766 |
{ |
| 767 |
return SoftHSM::i()->C_SignInit(hSession, pMechanism, hKey); |
| 768 |
} |
| 769 |
catch (...) |
| 770 |
{ |
| 771 |
FatalException(); |
| 772 |
} |
| 773 |
|
| 774 |
return CKR_FUNCTION_FAILED; |
| 775 |
} |
| 776 |
|
| 777 |
// Sign the data in a single pass operation |
| 778 |
PKCS_API CK_RV C_Sign(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen) |
| 779 |
{ |
| 780 |
try |
| 781 |
{ |
| 782 |
return SoftHSM::i()->C_Sign(hSession, pData, ulDataLen, pSignature, pulSignatureLen); |
| 783 |
} |
| 784 |
catch (...) |
| 785 |
{ |
| 786 |
FatalException(); |
| 787 |
} |
| 788 |
|
| 789 |
return CKR_FUNCTION_FAILED; |
| 790 |
} |
| 791 |
|
| 792 |
// Update a running signing operation with additional data |
| 793 |
PKCS_API CK_RV C_SignUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen) |
| 794 |
{ |
| 795 |
try |
| 796 |
{ |
| 797 |
return SoftHSM::i()->C_SignUpdate(hSession, pPart, ulPartLen); |
| 798 |
} |
| 799 |
catch (...) |
| 800 |
{ |
| 801 |
FatalException(); |
| 802 |
} |
| 803 |
|
| 804 |
return CKR_FUNCTION_FAILED; |
| 805 |
} |
| 806 |
|
| 807 |
// Finalise a running signing operation and return the signature |
| 808 |
PKCS_API CK_RV C_SignFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen) |
| 809 |
{ |
| 810 |
try |
| 811 |
{ |
| 812 |
return SoftHSM::i()->C_SignFinal(hSession, pSignature, pulSignatureLen); |
| 813 |
} |
| 814 |
catch (...) |
| 815 |
{ |
| 816 |
FatalException(); |
| 817 |
} |
| 818 |
|
| 819 |
return CKR_FUNCTION_FAILED; |
| 820 |
} |
| 821 |
|
| 822 |
// Initialise a signing operation that allows recovery of the signed data |
| 823 |
PKCS_API CK_RV C_SignRecoverInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey) |
| 824 |
{ |
| 825 |
try |
| 826 |
{ |
| 827 |
return SoftHSM::i()->C_SignRecoverInit(hSession, pMechanism, hKey); |
| 828 |
} |
| 829 |
catch (...) |
| 830 |
{ |
| 831 |
FatalException(); |
| 832 |
} |
| 833 |
|
| 834 |
return CKR_FUNCTION_FAILED; |
| 835 |
} |
| 836 |
|
| 837 |
// Perform a single part signing operation that allows recovery of the signed data |
| 838 |
PKCS_API CK_RV C_SignRecover(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen) |
| 839 |
{ |
| 840 |
try |
| 841 |
{ |
| 842 |
return SoftHSM::i()->C_SignRecover(hSession, pData, ulDataLen, pSignature, pulSignatureLen); |
| 843 |
} |
| 844 |
catch (...) |
| 845 |
{ |
| 846 |
FatalException(); |
| 847 |
} |
| 848 |
|
| 849 |
return CKR_FUNCTION_FAILED; |
| 850 |
} |
| 851 |
|
| 852 |
// Initialise a verification operation using the specified key and mechanism |
| 853 |
PKCS_API CK_RV C_VerifyInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey) |
| 854 |
{ |
| 855 |
try |
| 856 |
{ |
| 857 |
return SoftHSM::i()->C_VerifyInit(hSession, pMechanism, hKey); |
| 858 |
} |
| 859 |
catch (...) |
| 860 |
{ |
| 861 |
FatalException(); |
| 862 |
} |
| 863 |
|
| 864 |
return CKR_FUNCTION_FAILED; |
| 865 |
} |
| 866 |
|
| 867 |
// Perform a single pass verification operation |
| 868 |
PKCS_API CK_RV C_Verify(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen) |
| 869 |
{ |
| 870 |
try |
| 871 |
{ |
| 872 |
return SoftHSM::i()->C_Verify(hSession, pData, ulDataLen, pSignature, ulSignatureLen); |
| 873 |
} |
| 874 |
catch (...) |
| 875 |
{ |
| 876 |
FatalException(); |
| 877 |
} |
| 878 |
|
| 879 |
return CKR_FUNCTION_FAILED; |
| 880 |
} |
| 881 |
|
| 882 |
// Update a running verification operation with additional data |
| 883 |
PKCS_API CK_RV C_VerifyUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen) |
| 884 |
{ |
| 885 |
try |
| 886 |
{ |
| 887 |
return SoftHSM::i()->C_VerifyUpdate(hSession, pPart, ulPartLen); |
| 888 |
} |
| 889 |
catch (...) |
| 890 |
{ |
| 891 |
FatalException(); |
| 892 |
} |
| 893 |
|
| 894 |
return CKR_FUNCTION_FAILED; |
| 895 |
} |
| 896 |
|
| 897 |
// Finalise the verification operation and check the signature |
| 898 |
PKCS_API CK_RV C_VerifyFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen) |
| 899 |
{ |
| 900 |
try |
| 901 |
{ |
| 902 |
return SoftHSM::i()->C_VerifyFinal(hSession, pSignature, ulSignatureLen); |
| 903 |
} |
| 904 |
catch (...) |
| 905 |
{ |
| 906 |
FatalException(); |
| 907 |
} |
| 908 |
|
| 909 |
return CKR_FUNCTION_FAILED; |
| 910 |
} |
| 911 |
|
| 912 |
// Initialise a verification operation the allows recovery of the signed data from the signature |
| 913 |
PKCS_API CK_RV C_VerifyRecoverInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey) |
| 914 |
{ |
| 915 |
try |
| 916 |
{ |
| 917 |
return SoftHSM::i()->C_VerifyRecoverInit(hSession, pMechanism, hKey); |
| 918 |
} |
| 919 |
catch (...) |
| 920 |
{ |
| 921 |
FatalException(); |
| 922 |
} |
| 923 |
|
| 924 |
return CKR_FUNCTION_FAILED; |
| 925 |
} |
| 926 |
|
| 927 |
// Perform a single part verification operation and recover the signed data |
| 928 |
PKCS_API CK_RV C_VerifyRecover(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen, CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen) |
| 929 |
{ |
| 930 |
try |
| 931 |
{ |
| 932 |
return SoftHSM::i()->C_VerifyRecover(hSession, pSignature, ulSignatureLen, pData, pulDataLen); |
| 933 |
} |
| 934 |
catch (...) |
| 935 |
{ |
| 936 |
FatalException(); |
| 937 |
} |
| 938 |
|
| 939 |
return CKR_FUNCTION_FAILED; |
| 940 |
} |
| 941 |
|
| 942 |
// Update a running multi-part encryption and digesting operation |
| 943 |
PKCS_API CK_RV C_DigestEncryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart, CK_ULONG_PTR pulEncryptedPartLen) |
| 944 |
{ |
| 945 |
try |
| 946 |
{ |
| 947 |
return SoftHSM::i()->C_DigestEncryptUpdate(hSession, pPart, ulPartLen, pEncryptedPart, pulEncryptedPartLen); |
| 948 |
} |
| 949 |
catch (...) |
| 950 |
{ |
| 951 |
FatalException(); |
| 952 |
} |
| 953 |
|
| 954 |
return CKR_FUNCTION_FAILED; |
| 955 |
} |
| 956 |
|
| 957 |
// Update a running multi-part decryption and digesting operation |
| 958 |
PKCS_API CK_RV C_DecryptDigestUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen, CK_BYTE_PTR pDecryptedPart, CK_ULONG_PTR pulDecryptedPartLen) |
| 959 |
{ |
| 960 |
try |
| 961 |
{ |
| 962 |
return SoftHSM::i()->C_DecryptDigestUpdate(hSession, pPart, ulPartLen, pDecryptedPart, pulDecryptedPartLen); |
| 963 |
} |
| 964 |
catch (...) |
| 965 |
{ |
| 966 |
FatalException(); |
| 967 |
} |
| 968 |
|
| 969 |
return CKR_FUNCTION_FAILED; |
| 970 |
} |
| 971 |
|
| 972 |
// Update a running multi-part signing and encryption operation |
| 973 |
PKCS_API CK_RV C_SignEncryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart, CK_ULONG_PTR pulEncryptedPartLen) |
| 974 |
{ |
| 975 |
try |
| 976 |
{ |
| 977 |
return SoftHSM::i()->C_SignEncryptUpdate(hSession, pPart, ulPartLen, pEncryptedPart, pulEncryptedPartLen); |
| 978 |
} |
| 979 |
catch (...) |
| 980 |
{ |
| 981 |
FatalException(); |
| 982 |
} |
| 983 |
|
| 984 |
return CKR_FUNCTION_FAILED; |
| 985 |
} |
| 986 |
|
| 987 |
// Update a running multi-part decryption and verification operation |
| 988 |
PKCS_API CK_RV C_DecryptVerifyUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedPart, CK_ULONG ulEncryptedPartLen, CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen) |
| 989 |
{ |
| 990 |
try |
| 991 |
{ |
| 992 |
return SoftHSM::i()->C_DecryptVerifyUpdate(hSession, pEncryptedPart, ulEncryptedPartLen, pPart, pulPartLen); |
| 993 |
} |
| 994 |
catch (...) |
| 995 |
{ |
| 996 |
FatalException(); |
| 997 |
} |
| 998 |
|
| 999 |
return CKR_FUNCTION_FAILED; |
| 1000 |
} |
| 1001 |
|
| 1002 |
// Generate a secret key using the specified mechanism |
| 1003 |
PKCS_API CK_RV C_GenerateKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, CK_OBJECT_HANDLE_PTR phKey) |
| 1004 |
{ |
| 1005 |
try |
| 1006 |
{ |
| 1007 |
return SoftHSM::i()->C_GenerateKey(hSession, pMechanism, pTemplate, ulCount, phKey); |
| 1008 |
} |
| 1009 |
catch (...) |
| 1010 |
{ |
| 1011 |
FatalException(); |
| 1012 |
} |
| 1013 |
|
| 1014 |
return CKR_FUNCTION_FAILED; |
| 1015 |
} |
| 1016 |
|
| 1017 |
// Generate a key-pair using the specified mechanism |
| 1018 |
PKCS_API CK_RV C_GenerateKeyPair |
| 1019 |
( |
| 1020 |
CK_SESSION_HANDLE hSession, |
| 1021 |
CK_MECHANISM_PTR pMechanism, |
| 1022 |
CK_ATTRIBUTE_PTR pPublicKeyTemplate, |
| 1023 |
CK_ULONG ulPublicKeyAttributeCount, |
| 1024 |
CK_ATTRIBUTE_PTR pPrivateKeyTemplate, |
| 1025 |
CK_ULONG ulPrivateKeyAttributeCount, |
| 1026 |
CK_OBJECT_HANDLE_PTR phPublicKey, |
| 1027 |
CK_OBJECT_HANDLE_PTR phPrivateKey |
| 1028 |
) |
| 1029 |
{ |
| 1030 |
try |
| 1031 |
{ |
| 1032 |
return SoftHSM::i()->C_GenerateKeyPair(hSession, pMechanism, pPublicKeyTemplate, ulPublicKeyAttributeCount, pPrivateKeyTemplate, ulPrivateKeyAttributeCount, phPublicKey, phPrivateKey); |
| 1033 |
} |
| 1034 |
catch (...) |
| 1035 |
{ |
| 1036 |
FatalException(); |
| 1037 |
} |
| 1038 |
|
| 1039 |
return CKR_FUNCTION_FAILED; |
| 1040 |
} |
| 1041 |
|
| 1042 |
// Wrap the specified key using the specified wrapping key and mechanism |
| 1043 |
PKCS_API CK_RV C_WrapKey |
| 1044 |
( |
| 1045 |
CK_SESSION_HANDLE hSession, |
| 1046 |
CK_MECHANISM_PTR pMechanism, |
| 1047 |
CK_OBJECT_HANDLE hWrappingKey, |
| 1048 |
CK_OBJECT_HANDLE hKey, |
| 1049 |
CK_BYTE_PTR pWrappedKey, |
| 1050 |
CK_ULONG_PTR pulWrappedKeyLen |
| 1051 |
) |
| 1052 |
{ |
| 1053 |
try |
| 1054 |
{ |
| 1055 |
return SoftHSM::i()->C_WrapKey(hSession, pMechanism, hWrappingKey, hKey, pWrappedKey, pulWrappedKeyLen); |
| 1056 |
} |
| 1057 |
catch (...) |
| 1058 |
{ |
| 1059 |
FatalException(); |
| 1060 |
} |
| 1061 |
|
| 1062 |
return CKR_FUNCTION_FAILED; |
| 1063 |
} |
| 1064 |
|
| 1065 |
// Unwrap the specified key using the specified unwrapping key |
| 1066 |
PKCS_API CK_RV C_UnwrapKey |
| 1067 |
( |
| 1068 |
CK_SESSION_HANDLE hSession, |
| 1069 |
CK_MECHANISM_PTR pMechanism, |
| 1070 |
CK_OBJECT_HANDLE hUnwrappingKey, |
| 1071 |
CK_BYTE_PTR pWrappedKey, |
| 1072 |
CK_ULONG ulWrappedKeyLen, |
| 1073 |
CK_ATTRIBUTE_PTR pTemplate, |
| 1074 |
CK_ULONG ulCount, |
| 1075 |
CK_OBJECT_HANDLE_PTR phKey |
| 1076 |
) |
| 1077 |
{ |
| 1078 |
try |
| 1079 |
{ |
| 1080 |
return SoftHSM::i()->C_UnwrapKey(hSession, pMechanism, hUnwrappingKey, pWrappedKey, ulWrappedKeyLen, pTemplate, ulCount, phKey); |
| 1081 |
} |
| 1082 |
catch (...) |
| 1083 |
{ |
| 1084 |
FatalException(); |
| 1085 |
} |
| 1086 |
|
| 1087 |
return CKR_FUNCTION_FAILED; |
| 1088 |
} |
| 1089 |
|
| 1090 |
// Derive a key from the specified base key |
| 1091 |
PKCS_API CK_RV C_DeriveKey |
| 1092 |
( |
| 1093 |
CK_SESSION_HANDLE hSession, |
| 1094 |
CK_MECHANISM_PTR pMechanism, |
| 1095 |
CK_OBJECT_HANDLE hBaseKey, |
| 1096 |
CK_ATTRIBUTE_PTR pTemplate, |
| 1097 |
CK_ULONG ulCount, |
| 1098 |
CK_OBJECT_HANDLE_PTR phKey |
| 1099 |
) |
| 1100 |
{ |
| 1101 |
try |
| 1102 |
{ |
| 1103 |
return SoftHSM::i()->C_DeriveKey(hSession, pMechanism, hBaseKey, pTemplate, ulCount, phKey); |
| 1104 |
} |
| 1105 |
catch (...) |
| 1106 |
{ |
| 1107 |
FatalException(); |
| 1108 |
} |
| 1109 |
|
| 1110 |
return CKR_FUNCTION_FAILED; |
| 1111 |
} |
| 1112 |
|
| 1113 |
// Seed the random number generator with new data |
| 1114 |
PKCS_API CK_RV C_SeedRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSeed, CK_ULONG ulSeedLen) |
| 1115 |
{ |
| 1116 |
try |
| 1117 |
{ |
| 1118 |
return SoftHSM::i()->C_SeedRandom(hSession, pSeed, ulSeedLen); |
| 1119 |
} |
| 1120 |
catch (...) |
| 1121 |
{ |
| 1122 |
FatalException(); |
| 1123 |
} |
| 1124 |
|
| 1125 |
return CKR_FUNCTION_FAILED; |
| 1126 |
} |
| 1127 |
|
| 1128 |
// Generate the specified amount of random data |
| 1129 |
PKCS_API CK_RV C_GenerateRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pRandomData, CK_ULONG ulRandomLen) |
| 1130 |
{ |
| 1131 |
try |
| 1132 |
{ |
| 1133 |
return SoftHSM::i()->C_GenerateRandom(hSession, pRandomData, ulRandomLen); |
| 1134 |
} |
| 1135 |
catch (...) |
| 1136 |
{ |
| 1137 |
FatalException(); |
| 1138 |
} |
| 1139 |
|
| 1140 |
return CKR_FUNCTION_FAILED; |
| 1141 |
} |
| 1142 |
|
| 1143 |
// Legacy function |
| 1144 |
PKCS_API CK_RV C_GetFunctionStatus(CK_SESSION_HANDLE hSession) |
| 1145 |
{ |
| 1146 |
try |
| 1147 |
{ |
| 1148 |
return SoftHSM::i()->C_GetFunctionStatus(hSession); |
| 1149 |
} |
| 1150 |
catch (...) |
| 1151 |
{ |
| 1152 |
FatalException(); |
| 1153 |
} |
| 1154 |
|
| 1155 |
return CKR_FUNCTION_FAILED; |
| 1156 |
} |
| 1157 |
|
| 1158 |
// Legacy function |
| 1159 |
PKCS_API CK_RV C_CancelFunction(CK_SESSION_HANDLE hSession) |
| 1160 |
{ |
| 1161 |
try |
| 1162 |
{ |
| 1163 |
return SoftHSM::i()->C_CancelFunction(hSession); |
| 1164 |
} |
| 1165 |
catch (...) |
| 1166 |
{ |
| 1167 |
FatalException(); |
| 1168 |
} |
| 1169 |
|
| 1170 |
return CKR_FUNCTION_FAILED; |
| 1171 |
} |
| 1172 |
|
| 1173 |
// Wait or poll for a slot even on the specified slot |
| 1174 |
PKCS_API CK_RV C_WaitForSlotEvent(CK_FLAGS flags, CK_SLOT_ID_PTR pSlot, CK_VOID_PTR pReserved) |
| 1175 |
{ |
| 1176 |
try |
| 1177 |
{ |
| 1178 |
return SoftHSM::i()->C_WaitForSlotEvent(flags, pSlot, pReserved); |
| 1179 |
} |
| 1180 |
catch (...) |
| 1181 |
{ |
| 1182 |
FatalException(); |
| 1183 |
} |
| 1184 |
|
| 1185 |
return CKR_FUNCTION_FAILED; |
| 1186 |
} |
| 1187 |
|