| 1 |
/* |
| 2 |
* Copyright (c) 2010 .SE (The Internet Infrastructure Foundation) |
| 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 |
softhsm2-util.h |
| 29 |
|
| 30 |
This program can be used for interacting with HSMs using PKCS#11. |
| 31 |
The default library is the libsofthsm2.so |
| 32 |
*****************************************************************************/ |
| 33 |
|
| 34 |
#ifndef _SOFTHSM_V2_SOFTHSM2_UTIL_H |
| 35 |
#define _SOFTHSM_V2_SOFTHSM2_UTIL_H |
| 36 |
|
| 37 |
#include "cryptoki.h" |
| 38 |
#include <string> |
| 39 |
|
| 40 |
// Main functions |
| 41 |
|
| 42 |
void usage(); |
| 43 |
bool checkSetup(); |
| 44 |
int initToken(CK_SLOT_ID slotID, char* label, char* soPIN, char* userPIN); |
| 45 |
bool deleteToken(char* serial, char* token); |
| 46 |
bool findTokenDirectory(std::string basedir, std::string& tokendir, char* serial, char* label); |
| 47 |
bool rmdir(std::string path); |
| 48 |
bool rm(std::string path); |
| 49 |
int showSlots(); |
| 50 |
int importKeyPair(char* filePath, char* filePIN, CK_SLOT_ID slotID, char* userPIN, char* objectLabel, char* objectID, int forceExec, int noPublicKey); |
| 51 |
int importSecretKey(char* filePath, CK_SLOT_ID slotID, char* userPIN, char* label, char* objectID); |
| 52 |
int crypto_import_key_pair(CK_SESSION_HANDLE hSession, char* filePath, char* filePIN, char* label, char* objID, size_t objIDLen, int noPublicKey); |
| 53 |
int crypto_import_aes_key(CK_SESSION_HANDLE hSession, char* filePath, char* label, char* objID, size_t objIDLen); |
| 54 |
|
| 55 |
// Support functions |
| 56 |
|
| 57 |
void crypto_init(); |
| 58 |
void crypto_final(); |
| 59 |
|
| 60 |
/// SoftHSM internal funtions |
| 61 |
bool initSoftHSM(); |
| 62 |
void finalizeSoftHSM(); |
| 63 |
|
| 64 |
/// Hex |
| 65 |
char* hexStrToBin(char* objectID, int idLength, size_t* newLen); |
| 66 |
int hexdigit_to_int(char ch); |
| 67 |
|
| 68 |
/// Library |
| 69 |
#if !defined(UTIL_BOTAN) && !defined(UTIL_OSSL) |
| 70 |
static void* moduleHandle; |
| 71 |
#endif |
| 72 |
extern CK_FUNCTION_LIST_PTR p11; |
| 73 |
|
| 74 |
/// PKCS#11 support |
| 75 |
CK_OBJECT_HANDLE searchObject(CK_SESSION_HANDLE hSession, char* objID, size_t objIDLen); |
| 76 |
|
| 77 |
#endif // !_SOFTHSM_V2_SOFTHSM2_UTIL_H |