|
Packit Service |
3749ba |
/*
|
|
Packit Service |
3749ba |
* Copyright (C) 2011 Collabora Ltd.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* Redistribution and use in source and binary forms, with or without
|
|
Packit Service |
3749ba |
* modification, are permitted provided that the following conditions
|
|
Packit Service |
3749ba |
* are met:
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* * Redistributions of source code must retain the above
|
|
Packit Service |
3749ba |
* copyright notice, this list of conditions and the
|
|
Packit Service |
3749ba |
* following disclaimer.
|
|
Packit Service |
3749ba |
* * Redistributions in binary form must reproduce the
|
|
Packit Service |
3749ba |
* above copyright notice, this list of conditions and
|
|
Packit Service |
3749ba |
* the following disclaimer in the documentation and/or
|
|
Packit Service |
3749ba |
* other materials provided with the distribution.
|
|
Packit Service |
3749ba |
* * The names of contributors to this software may not be
|
|
Packit Service |
3749ba |
* used to endorse or promote products derived from this
|
|
Packit Service |
3749ba |
* software without specific prior written permission.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit Service |
3749ba |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit Service |
3749ba |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
Packit Service |
3749ba |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
Packit Service |
3749ba |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
Packit Service |
3749ba |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
Packit Service |
3749ba |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
Packit Service |
3749ba |
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
Packit Service |
3749ba |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
Packit Service |
3749ba |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
Packit Service |
3749ba |
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
Packit Service |
3749ba |
* DAMAGE.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* Author: Stef Walter <stefw@collabora.co.uk>
|
|
Packit Service |
3749ba |
*/
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include "config.h"
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include "pkcs11.h"
|
|
Packit Service |
3749ba |
#include "p11-kit.h"
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
/**
|
|
Packit Service |
3749ba |
* SECTION:p11-kit-util
|
|
Packit Service |
3749ba |
* @title: Utilities
|
|
Packit Service |
3749ba |
* @short_description: PKCS\#11 utilities
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* Utility functions for working with PKCS\#11.
|
|
Packit Service |
3749ba |
*/
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#ifdef ENABLE_NLS
|
|
Packit Service |
3749ba |
#include <libintl.h>
|
|
Packit Service |
3749ba |
#define _(x) dgettext(PACKAGE_NAME, x)
|
|
Packit Service |
3749ba |
#else
|
|
Packit Service |
3749ba |
#define _(x) x
|
|
Packit Service |
3749ba |
#endif
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
/**
|
|
Packit Service |
3749ba |
* p11_kit_strerror:
|
|
Packit Service |
3749ba |
* @rv: The code to get a message for.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* Get a message for a PKCS\#11 return value or error code. Do not
|
|
Packit Service |
3749ba |
* pass CKR_OK or other such non errors to this function.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* Returns: The user readable and localized message.
|
|
Packit Service |
3749ba |
**/
|
|
Packit Service |
3749ba |
const char*
|
|
Packit Service |
3749ba |
p11_kit_strerror (CK_RV rv)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
switch (rv) {
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
/* These are not really errors, or not current */
|
|
Packit Service |
3749ba |
case CKR_OK:
|
|
Packit Service |
3749ba |
case CKR_NO_EVENT:
|
|
Packit Service |
3749ba |
case CKR_FUNCTION_NOT_PARALLEL:
|
|
Packit Service |
3749ba |
case CKR_SESSION_PARALLEL_NOT_SUPPORTED:
|
|
Packit Service |
3749ba |
return "";
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
case CKR_CANCEL:
|
|
Packit Service |
3749ba |
case CKR_FUNCTION_CANCELED:
|
|
Packit Service |
3749ba |
return _("The operation was cancelled");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
case CKR_HOST_MEMORY:
|
|
Packit Service |
3749ba |
return _("Insufficient memory available");
|
|
Packit Service |
3749ba |
case CKR_SLOT_ID_INVALID:
|
|
Packit Service |
3749ba |
return _("The specified slot ID is not valid");
|
|
Packit Service |
3749ba |
case CKR_GENERAL_ERROR:
|
|
Packit Service |
3749ba |
return _("Internal error");
|
|
Packit Service |
3749ba |
case CKR_FUNCTION_FAILED:
|
|
Packit Service |
3749ba |
return _("The operation failed");
|
|
Packit Service |
3749ba |
case CKR_ARGUMENTS_BAD:
|
|
Packit Service |
3749ba |
return _("Invalid arguments");
|
|
Packit Service |
3749ba |
case CKR_NEED_TO_CREATE_THREADS:
|
|
Packit Service |
3749ba |
return _("The module cannot create needed threads");
|
|
Packit Service |
3749ba |
case CKR_CANT_LOCK:
|
|
Packit Service |
3749ba |
return _("The module cannot lock data properly");
|
|
Packit Service |
3749ba |
case CKR_ATTRIBUTE_READ_ONLY:
|
|
Packit Service |
3749ba |
return _("The field is read-only");
|
|
Packit Service |
3749ba |
case CKR_ATTRIBUTE_SENSITIVE:
|
|
Packit Service |
3749ba |
return _("The field is sensitive and cannot be revealed");
|
|
Packit Service |
3749ba |
case CKR_ATTRIBUTE_TYPE_INVALID:
|
|
Packit Service |
3749ba |
return _("The field is invalid or does not exist");
|
|
Packit Service |
3749ba |
case CKR_ATTRIBUTE_VALUE_INVALID:
|
|
Packit Service |
3749ba |
return _("Invalid value for field");
|
|
Packit Service |
3749ba |
case CKR_DATA_INVALID:
|
|
Packit Service |
3749ba |
return _("The data is not valid or unrecognized");
|
|
Packit Service |
3749ba |
case CKR_DATA_LEN_RANGE:
|
|
Packit Service |
3749ba |
return _("The data is too long");
|
|
Packit Service |
3749ba |
case CKR_DEVICE_ERROR:
|
|
Packit Service |
3749ba |
return _("An error occurred on the device");
|
|
Packit Service |
3749ba |
case CKR_DEVICE_MEMORY:
|
|
Packit Service |
3749ba |
return _("Insufficient memory available on the device");
|
|
Packit Service |
3749ba |
case CKR_DEVICE_REMOVED:
|
|
Packit Service |
3749ba |
return _("The device was removed or unplugged");
|
|
Packit Service |
3749ba |
case CKR_ENCRYPTED_DATA_INVALID:
|
|
Packit Service |
3749ba |
return _("The encrypted data is not valid or unrecognized");
|
|
Packit Service |
3749ba |
case CKR_ENCRYPTED_DATA_LEN_RANGE:
|
|
Packit Service |
3749ba |
return _("The encrypted data is too long");
|
|
Packit Service |
3749ba |
case CKR_FUNCTION_NOT_SUPPORTED:
|
|
Packit Service |
3749ba |
return _("This operation is not supported");
|
|
Packit Service |
3749ba |
case CKR_KEY_HANDLE_INVALID:
|
|
Packit Service |
3749ba |
return _("The key is missing or invalid");
|
|
Packit Service |
3749ba |
case CKR_KEY_SIZE_RANGE:
|
|
Packit Service |
3749ba |
return _("The key is the wrong size");
|
|
Packit Service |
3749ba |
case CKR_KEY_TYPE_INCONSISTENT:
|
|
Packit Service |
3749ba |
return _("The key is of the wrong type");
|
|
Packit Service |
3749ba |
case CKR_KEY_NOT_NEEDED:
|
|
Packit Service |
3749ba |
return _("No key is needed");
|
|
Packit Service |
3749ba |
case CKR_KEY_CHANGED:
|
|
Packit Service |
3749ba |
return _("The key is different than before");
|
|
Packit Service |
3749ba |
case CKR_KEY_NEEDED:
|
|
Packit Service |
3749ba |
return _("A key is needed");
|
|
Packit Service |
3749ba |
case CKR_KEY_INDIGESTIBLE:
|
|
Packit Service |
3749ba |
return _("Cannot include the key in the digest");
|
|
Packit Service |
3749ba |
case CKR_KEY_FUNCTION_NOT_PERMITTED:
|
|
Packit Service |
3749ba |
return _("This operation cannot be done with this key");
|
|
Packit Service |
3749ba |
case CKR_KEY_NOT_WRAPPABLE:
|
|
Packit Service |
3749ba |
return _("The key cannot be wrapped");
|
|
Packit Service |
3749ba |
case CKR_KEY_UNEXTRACTABLE:
|
|
Packit Service |
3749ba |
return _("Cannot export this key");
|
|
Packit Service |
3749ba |
case CKR_MECHANISM_INVALID:
|
|
Packit Service |
3749ba |
return _("The crypto mechanism is invalid or unrecognized");
|
|
Packit Service |
3749ba |
case CKR_MECHANISM_PARAM_INVALID:
|
|
Packit Service |
3749ba |
return _("The crypto mechanism has an invalid argument");
|
|
Packit Service |
3749ba |
case CKR_OBJECT_HANDLE_INVALID:
|
|
Packit Service |
3749ba |
return _("The object is missing or invalid");
|
|
Packit Service |
3749ba |
case CKR_OPERATION_ACTIVE:
|
|
Packit Service |
3749ba |
return _("Another operation is already taking place");
|
|
Packit Service |
3749ba |
case CKR_OPERATION_NOT_INITIALIZED:
|
|
Packit Service |
3749ba |
return _("No operation is taking place");
|
|
Packit Service |
3749ba |
case CKR_PIN_INCORRECT:
|
|
Packit Service |
3749ba |
return _("The password or PIN is incorrect");
|
|
Packit Service |
3749ba |
case CKR_PIN_INVALID:
|
|
Packit Service |
3749ba |
return _("The password or PIN is invalid");
|
|
Packit Service |
3749ba |
case CKR_PIN_LEN_RANGE:
|
|
Packit Service |
3749ba |
return _("The password or PIN is of an invalid length");
|
|
Packit Service |
3749ba |
case CKR_PIN_EXPIRED:
|
|
Packit Service |
3749ba |
return _("The password or PIN has expired");
|
|
Packit Service |
3749ba |
case CKR_PIN_LOCKED:
|
|
Packit Service |
3749ba |
return _("The password or PIN is locked");
|
|
Packit Service |
3749ba |
case CKR_SESSION_CLOSED:
|
|
Packit Service |
3749ba |
return _("The session is closed");
|
|
Packit Service |
3749ba |
case CKR_SESSION_COUNT:
|
|
Packit Service |
3749ba |
return _("Too many sessions are active");
|
|
Packit Service |
3749ba |
case CKR_SESSION_HANDLE_INVALID:
|
|
Packit Service |
3749ba |
return _("The session is invalid");
|
|
Packit Service |
3749ba |
case CKR_SESSION_READ_ONLY:
|
|
Packit Service |
3749ba |
return _("The session is read-only");
|
|
Packit Service |
3749ba |
case CKR_SESSION_EXISTS:
|
|
Packit Service |
3749ba |
return _("An open session exists");
|
|
Packit Service |
3749ba |
case CKR_SESSION_READ_ONLY_EXISTS:
|
|
Packit Service |
3749ba |
return _("A read-only session exists");
|
|
Packit Service |
3749ba |
case CKR_SESSION_READ_WRITE_SO_EXISTS:
|
|
Packit Service |
3749ba |
return _("An administrator session exists");
|
|
Packit Service |
3749ba |
case CKR_SIGNATURE_INVALID:
|
|
Packit Service |
3749ba |
return _("The signature is bad or corrupted");
|
|
Packit Service |
3749ba |
case CKR_SIGNATURE_LEN_RANGE:
|
|
Packit Service |
3749ba |
return _("The signature is unrecognized or corrupted");
|
|
Packit Service |
3749ba |
case CKR_TEMPLATE_INCOMPLETE:
|
|
Packit Service |
3749ba |
return _("Certain required fields are missing");
|
|
Packit Service |
3749ba |
case CKR_TEMPLATE_INCONSISTENT:
|
|
Packit Service |
3749ba |
return _("Certain fields have invalid values");
|
|
Packit Service |
3749ba |
case CKR_TOKEN_NOT_PRESENT:
|
|
Packit Service |
3749ba |
return _("The device is not present or unplugged");
|
|
Packit Service |
3749ba |
case CKR_TOKEN_NOT_RECOGNIZED:
|
|
Packit Service |
3749ba |
return _("The device is invalid or unrecognizable");
|
|
Packit Service |
3749ba |
case CKR_TOKEN_WRITE_PROTECTED:
|
|
Packit Service |
3749ba |
return _("The device is write protected");
|
|
Packit Service |
3749ba |
case CKR_UNWRAPPING_KEY_HANDLE_INVALID:
|
|
Packit Service |
3749ba |
return _("Cannot import because the key is invalid");
|
|
Packit Service |
3749ba |
case CKR_UNWRAPPING_KEY_SIZE_RANGE:
|
|
Packit Service |
3749ba |
return _("Cannot import because the key is of the wrong size");
|
|
Packit Service |
3749ba |
case CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT:
|
|
Packit Service |
3749ba |
return _("Cannot import because the key is of the wrong type");
|
|
Packit Service |
3749ba |
case CKR_USER_ALREADY_LOGGED_IN:
|
|
Packit Service |
3749ba |
return _("You are already logged in");
|
|
Packit Service |
3749ba |
case CKR_USER_NOT_LOGGED_IN:
|
|
Packit Service |
3749ba |
return _("No user has logged in");
|
|
Packit Service |
3749ba |
case CKR_USER_PIN_NOT_INITIALIZED:
|
|
Packit Service |
3749ba |
return _("The user's password or PIN is not set");
|
|
Packit Service |
3749ba |
case CKR_USER_TYPE_INVALID:
|
|
Packit Service |
3749ba |
return _("The user is of an invalid type");
|
|
Packit Service |
3749ba |
case CKR_USER_ANOTHER_ALREADY_LOGGED_IN:
|
|
Packit Service |
3749ba |
return _("Another user is already logged in");
|
|
Packit Service |
3749ba |
case CKR_USER_TOO_MANY_TYPES:
|
|
Packit Service |
3749ba |
return _("Too many users of different types are logged in");
|
|
Packit Service |
3749ba |
case CKR_WRAPPED_KEY_INVALID:
|
|
Packit Service |
3749ba |
return _("Cannot import an invalid key");
|
|
Packit Service |
3749ba |
case CKR_WRAPPED_KEY_LEN_RANGE:
|
|
Packit Service |
3749ba |
return _("Cannot import a key of the wrong size");
|
|
Packit Service |
3749ba |
case CKR_WRAPPING_KEY_HANDLE_INVALID:
|
|
Packit Service |
3749ba |
return _("Cannot export because the key is invalid");
|
|
Packit Service |
3749ba |
case CKR_WRAPPING_KEY_SIZE_RANGE:
|
|
Packit Service |
3749ba |
return _("Cannot export because the key is of the wrong size");
|
|
Packit Service |
3749ba |
case CKR_WRAPPING_KEY_TYPE_INCONSISTENT:
|
|
Packit Service |
3749ba |
return _("Cannot export because the key is of the wrong type");
|
|
Packit Service |
3749ba |
case CKR_RANDOM_SEED_NOT_SUPPORTED:
|
|
Packit Service |
3749ba |
return _("Unable to initialize the random number generator");
|
|
Packit Service |
3749ba |
case CKR_RANDOM_NO_RNG:
|
|
Packit Service |
3749ba |
return _("No random number generator available");
|
|
Packit Service |
3749ba |
case CKR_DOMAIN_PARAMS_INVALID:
|
|
Packit Service |
3749ba |
return _("The crypto mechanism has an invalid parameter");
|
|
Packit Service |
3749ba |
case CKR_BUFFER_TOO_SMALL:
|
|
Packit Service |
3749ba |
return _("Not enough space to store the result");
|
|
Packit Service |
3749ba |
case CKR_SAVED_STATE_INVALID:
|
|
Packit Service |
3749ba |
return _("The saved state is invalid");
|
|
Packit Service |
3749ba |
case CKR_INFORMATION_SENSITIVE:
|
|
Packit Service |
3749ba |
return _("The information is sensitive and cannot be revealed");
|
|
Packit Service |
3749ba |
case CKR_STATE_UNSAVEABLE:
|
|
Packit Service |
3749ba |
return _("The state cannot be saved");
|
|
Packit Service |
3749ba |
case CKR_CRYPTOKI_NOT_INITIALIZED:
|
|
Packit Service |
3749ba |
return _("The module has not been initialized");
|
|
Packit Service |
3749ba |
case CKR_CRYPTOKI_ALREADY_INITIALIZED:
|
|
Packit Service |
3749ba |
return _("The module has already been initialized");
|
|
Packit Service |
3749ba |
case CKR_MUTEX_BAD:
|
|
Packit Service |
3749ba |
return _("Cannot lock data");
|
|
Packit Service |
3749ba |
case CKR_MUTEX_NOT_LOCKED:
|
|
Packit Service |
3749ba |
return _("The data cannot be locked");
|
|
Packit Service |
3749ba |
case CKR_FUNCTION_REJECTED:
|
|
Packit Service |
3749ba |
return _("The request was rejected by the user");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
default:
|
|
Packit Service |
3749ba |
return _("Unknown error");
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
}
|