363N/A/*
7161N/A * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
363N/A */
363N/A
2385N/A/* crypto/engine/e_pk11_err.c */
363N/A/*
363N/A * This product includes software developed by the OpenSSL Project for
363N/A * use in the OpenSSL Toolkit (http://www.openssl.org/).
363N/A *
363N/A * This project also referenced hw_pkcs11-0.9.7b.patch written by
363N/A * Afchine Madjlessi.
363N/A */
363N/A/*
363N/A * ====================================================================
363N/A * Copyright (c) 2000-2001 The OpenSSL Project. All rights reserved.
363N/A *
363N/A * Redistribution and use in source and binary forms, with or without
363N/A * modification, are permitted provided that the following conditions
363N/A * are met:
363N/A *
363N/A * 1. Redistributions of source code must retain the above copyright
363N/A * notice, this list of conditions and the following disclaimer.
363N/A *
363N/A * 2. Redistributions in binary form must reproduce the above copyright
363N/A * notice, this list of conditions and the following disclaimer in
363N/A * the documentation and/or other materials provided with the
363N/A * distribution.
363N/A *
363N/A * 3. All advertising materials mentioning features or use of this
363N/A * software must display the following acknowledgment:
363N/A * "This product includes software developed by the OpenSSL Project
363N/A * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
363N/A *
363N/A * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
363N/A * endorse or promote products derived from this software without
363N/A * prior written permission. For written permission, please contact
363N/A * licensing@OpenSSL.org.
363N/A *
363N/A * 5. Products derived from this software may not be called "OpenSSL"
363N/A * nor may "OpenSSL" appear in their names without prior written
363N/A * permission of the OpenSSL Project.
363N/A *
363N/A * 6. Redistributions of any form whatsoever must retain the following
363N/A * acknowledgment:
363N/A * "This product includes software developed by the OpenSSL Project
363N/A * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
363N/A *
363N/A * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
363N/A * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
363N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
363N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
363N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
363N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
363N/A * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
363N/A * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
363N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
363N/A * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
363N/A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
363N/A * OF THE POSSIBILITY OF SUCH DAMAGE.
363N/A * ====================================================================
363N/A *
363N/A * This product includes cryptographic software written by Eric Young
363N/A * (eay@cryptsoft.com). This product includes software written by Tim
363N/A * Hudson (tjh@cryptsoft.com).
363N/A *
363N/A */
363N/A
363N/A#include <stdio.h>
363N/A#include <openssl/err.h>
2385N/A#include "e_pk11_err.h"
363N/A
363N/A/* BEGIN ERROR CODES */
363N/A#ifndef OPENSSL_NO_ERR
363N/Astatic ERR_STRING_DATA pk11_str_functs[]=
363N/A{
363N/A{ ERR_PACK(0, PK11_F_INIT, 0), "PK11_INIT"},
363N/A{ ERR_PACK(0, PK11_F_FINISH, 0), "PK11_FINISH"},
363N/A{ ERR_PACK(0, PK11_F_DESTROY, 0), "PK11_DESTROY"},
363N/A{ ERR_PACK(0, PK11_F_CTRL, 0), "PK11_CTRL"},
363N/A{ ERR_PACK(0, PK11_F_RSA_INIT, 0), "PK11_RSA_INIT"},
363N/A{ ERR_PACK(0, PK11_F_RSA_FINISH, 0), "PK11_RSA_FINISH"},
363N/A{ ERR_PACK(0, PK11_F_GET_PUB_RSA_KEY, 0), "PK11_GET_PUB_RSA_KEY"},
363N/A{ ERR_PACK(0, PK11_F_GET_PRIV_RSA_KEY, 0), "PK11_GET_PRIV_RSA_KEY"},
363N/A{ ERR_PACK(0, PK11_F_RSA_GEN_KEY, 0), "PK11_RSA_GEN_KEY"},
363N/A{ ERR_PACK(0, PK11_F_RSA_PUB_ENC, 0), "PK11_RSA_PUB_ENC"},
363N/A{ ERR_PACK(0, PK11_F_RSA_PRIV_ENC, 0), "PK11_RSA_PRIV_ENC"},
363N/A{ ERR_PACK(0, PK11_F_RSA_PUB_DEC, 0), "PK11_RSA_PUB_DEC"},
363N/A{ ERR_PACK(0, PK11_F_RSA_PRIV_DEC, 0), "PK11_RSA_PRIV_DEC"},
363N/A{ ERR_PACK(0, PK11_F_RSA_SIGN, 0), "PK11_RSA_SIGN"},
363N/A{ ERR_PACK(0, PK11_F_RSA_VERIFY, 0), "PK11_RSA_VERIFY"},
363N/A{ ERR_PACK(0, PK11_F_RAND_ADD, 0), "PK11_RAND_ADD"},
363N/A{ ERR_PACK(0, PK11_F_RAND_BYTES, 0), "PK11_RAND_BYTES"},
363N/A{ ERR_PACK(0, PK11_F_GET_SESSION, 0), "PK11_GET_SESSION"},
363N/A{ ERR_PACK(0, PK11_F_FREE_SESSION, 0), "PK11_FREE_SESSION"},
363N/A{ ERR_PACK(0, PK11_F_LOAD_PUBKEY, 0), "PK11_LOAD_PUBKEY"},
363N/A{ ERR_PACK(0, PK11_F_LOAD_PRIVKEY, 0), "PK11_LOAD_PRIV_KEY"},
363N/A{ ERR_PACK(0, PK11_F_RSA_PUB_ENC_LOW, 0), "PK11_RSA_PUB_ENC_LOW"},
363N/A{ ERR_PACK(0, PK11_F_RSA_PRIV_ENC_LOW, 0), "PK11_RSA_PRIV_ENC_LOW"},
363N/A{ ERR_PACK(0, PK11_F_RSA_PUB_DEC_LOW, 0), "PK11_RSA_PUB_DEC_LOW"},
363N/A{ ERR_PACK(0, PK11_F_RSA_PRIV_DEC_LOW, 0), "PK11_RSA_PRIV_DEC_LOW"},
363N/A{ ERR_PACK(0, PK11_F_DSA_SIGN, 0), "PK11_DSA_SIGN"},
363N/A{ ERR_PACK(0, PK11_F_DSA_VERIFY, 0), "PK11_DSA_VERIFY"},
363N/A{ ERR_PACK(0, PK11_F_DSA_INIT, 0), "PK11_DSA_INIT"},
363N/A{ ERR_PACK(0, PK11_F_DSA_FINISH, 0), "PK11_DSA_FINISH"},
363N/A{ ERR_PACK(0, PK11_F_GET_PUB_DSA_KEY, 0), "PK11_GET_PUB_DSA_KEY"},
363N/A{ ERR_PACK(0, PK11_F_GET_PRIV_DSA_KEY, 0), "PK11_GET_PRIV_DSA_KEY"},
363N/A{ ERR_PACK(0, PK11_F_DH_INIT, 0), "PK11_DH_INIT"},
363N/A{ ERR_PACK(0, PK11_F_DH_FINISH, 0), "PK11_DH_FINISH"},
363N/A{ ERR_PACK(0, PK11_F_MOD_EXP_DH, 0), "PK11_MOD_EXP_DH"},
363N/A{ ERR_PACK(0, PK11_F_GET_DH_KEY, 0), "PK11_GET_DH_KEY"},
363N/A{ ERR_PACK(0, PK11_F_FREE_ALL_SESSIONS, 0), "PK11_FREE_ALL_SESSIONS"},
363N/A{ ERR_PACK(0, PK11_F_SETUP_SESSION, 0), "PK11_SETUP_SESSION"},
363N/A{ ERR_PACK(0, PK11_F_DESTROY_OBJECT, 0), "PK11_DESTROY_OBJECT"},
363N/A{ ERR_PACK(0, PK11_F_CIPHER_INIT, 0), "PK11_CIPHER_INIT"},
363N/A{ ERR_PACK(0, PK11_F_CIPHER_DO_CIPHER, 0), "PK11_CIPHER_DO_CIPHER"},
363N/A{ ERR_PACK(0, PK11_F_GET_CIPHER_KEY, 0), "PK11_GET_CIPHER_KEY"},
363N/A{ ERR_PACK(0, PK11_F_DIGEST_INIT, 0), "PK11_DIGEST_INIT"},
363N/A{ ERR_PACK(0, PK11_F_DIGEST_UPDATE, 0), "PK11_DIGEST_UPDATE"},
363N/A{ ERR_PACK(0, PK11_F_DIGEST_FINAL, 0), "PK11_DIGEST_FINAL"},
363N/A{ ERR_PACK(0, PK11_F_CHOOSE_SLOT, 0), "PK11_CHOOSE_SLOT"},
363N/A{ ERR_PACK(0, PK11_F_CIPHER_FINAL, 0), "PK11_CIPHER_FINAL"},
363N/A{ ERR_PACK(0, PK11_F_LIBRARY_INIT, 0), "PK11_LIBRARY_INIT"},
363N/A{ ERR_PACK(0, PK11_F_LOAD, 0), "ENGINE_LOAD_PK11"},
363N/A{ ERR_PACK(0, PK11_F_DH_GEN_KEY, 0), "PK11_DH_GEN_KEY"},
363N/A{ ERR_PACK(0, PK11_F_DH_COMP_KEY, 0), "PK11_DH_COMP_KEY"},
363N/A{ ERR_PACK(0, PK11_F_DIGEST_COPY, 0), "PK11_DIGEST_COPY"},
363N/A{ ERR_PACK(0, PK11_F_CIPHER_CLEANUP, 0), "PK11_CIPHER_CLEANUP"},
363N/A{ ERR_PACK(0, PK11_F_ACTIVE_ADD, 0), "PK11_ACTIVE_ADD"},
363N/A{ ERR_PACK(0, PK11_F_ACTIVE_DELETE, 0), "PK11_ACTIVE_DELETE"},
363N/A{ ERR_PACK(0, PK11_F_CHECK_HW_MECHANISMS, 0), "PK11_CHECK_HW_MECHANISMS"},
363N/A{ ERR_PACK(0, PK11_F_INIT_SYMMETRIC, 0), "PK11_INIT_SYMMETRIC"},
363N/A{ ERR_PACK(0, PK11_F_ADD_AES_CTR_NIDS, 0), "PK11_ADD_AES_CTR_NIDS"},
363N/A{ ERR_PACK(0, PK11_F_INIT_ALL_LOCKS, 0), "PK11_INIT_ALL_LOCKS"},
363N/A{ ERR_PACK(0, PK11_F_RETURN_SESSION, 0), "PK11_RETURN_SESSION"},
363N/A{ ERR_PACK(0, PK11_F_GET_PIN, 0), "PK11_GET_PIN"},
363N/A{ ERR_PACK(0, PK11_F_FIND_ONE_OBJECT, 0), "PK11_FIND_ONE_OBJECT"},
363N/A{ ERR_PACK(0, PK11_F_CHECK_TOKEN_ATTRS, 0), "PK11_CHECK_TOKEN_ATTRS"},
363N/A{ ERR_PACK(0, PK11_F_CACHE_PIN, 0), "PK11_CACHE_PIN"},
363N/A{ ERR_PACK(0, PK11_F_MLOCK_PIN_IN_MEMORY, 0), "PK11_MLOCK_PIN_IN_MEMORY"},
363N/A{ ERR_PACK(0, PK11_F_TOKEN_LOGIN, 0), "PK11_TOKEN_LOGIN"},
363N/A{ ERR_PACK(0, PK11_F_TOKEN_RELOGIN, 0), "PK11_TOKEN_RELOGIN"},
363N/A{ ERR_PACK(0, PK11_F_RUN_ASKPASS, 0), "PK11_F_RUN_ASKPASS"},
363N/A{ 0, NULL}
363N/A};
363N/A
363N/Astatic ERR_STRING_DATA pk11_str_reasons[]=
363N/A{
363N/A{ PK11_R_ALREADY_LOADED, "PKCS#11 DSO already loaded"},
363N/A{ PK11_R_DSO_FAILURE, "unable to load PKCS#11 DSO"},
363N/A{ PK11_R_NOT_LOADED, "PKCS#11 DSO not loaded"},
363N/A{ PK11_R_PASSED_NULL_PARAMETER, "null parameter passed"},
363N/A{ PK11_R_COMMAND_NOT_IMPLEMENTED, "command not implemented"},
363N/A{ PK11_R_INITIALIZE, "C_Initialize failed"},
363N/A{ PK11_R_FINALIZE, "C_Finalize failed"},
363N/A{ PK11_R_GETINFO, "C_GetInfo faile"},
363N/A{ PK11_R_GETSLOTLIST, "C_GetSlotList failed"},
363N/A{ PK11_R_NO_MODULUS_OR_NO_EXPONENT, "no modulus or no exponent"},
363N/A{ PK11_R_ATTRIBUT_SENSITIVE_OR_INVALID, "attr sensitive or invalid"},
363N/A{ PK11_R_GETATTRIBUTVALUE, "C_GetAttributeValue failed"},
363N/A{ PK11_R_NO_MODULUS, "no modulus"},
363N/A{ PK11_R_NO_EXPONENT, "no exponent"},
363N/A{ PK11_R_FINDOBJECTSINIT, "C_FindObjectsInit failed"},
363N/A{ PK11_R_FINDOBJECTS, "C_FindObjects failed"},
363N/A{ PK11_R_FINDOBJECTSFINAL, "C_FindObjectsFinal failed"},
363N/A{ PK11_R_CREATEOBJECT, "C_CreateObject failed"},
363N/A{ PK11_R_DESTROYOBJECT, "C_DestroyObject failed"},
363N/A{ PK11_R_OPENSESSION, "C_OpenSession failed"},
363N/A{ PK11_R_CLOSESESSION, "C_CloseSession failed"},
363N/A{ PK11_R_ENCRYPTINIT, "C_EncryptInit failed"},
363N/A{ PK11_R_ENCRYPT, "C_Encrypt failed"},
363N/A{ PK11_R_SIGNINIT, "C_SignInit failed"},
363N/A{ PK11_R_SIGN, "C_Sign failed"},
363N/A{ PK11_R_DECRYPTINIT, "C_DecryptInit failed"},
363N/A{ PK11_R_DECRYPT, "C_Decrypt failed"},
363N/A{ PK11_R_VERIFYINIT, "C_VerifyRecover failed"},
363N/A{ PK11_R_VERIFY, "C_Verify failed"},
363N/A{ PK11_R_VERIFYRECOVERINIT, "C_VerifyRecoverInit failed"},
363N/A{ PK11_R_VERIFYRECOVER, "C_VerifyRecover failed"},
363N/A{ PK11_R_GEN_KEY, "C_GenerateKeyPair failed"},
363N/A{ PK11_R_SEEDRANDOM, "C_SeedRandom failed"},
363N/A{ PK11_R_GENERATERANDOM, "C_GenerateRandom failed"},
363N/A{ PK11_R_INVALID_MESSAGE_LENGTH, "invalid message length"},
363N/A{ PK11_R_UNKNOWN_ALGORITHM_TYPE, "unknown algorithm type"},
363N/A{ PK11_R_UNKNOWN_ASN1_OBJECT_ID, "unknown asn1 onject id"},
363N/A{ PK11_R_UNKNOWN_PADDING_TYPE, "unknown padding type"},
363N/A{ PK11_R_PADDING_CHECK_FAILED, "padding check failed"},
363N/A{ PK11_R_DIGEST_TOO_BIG, "digest too big"},
363N/A{ PK11_R_MALLOC_FAILURE, "malloc failure"},
363N/A{ PK11_R_CTRL_COMMAND_NOT_IMPLEMENTED, "ctl command not implemented"},
363N/A{ PK11_R_DATA_GREATER_THAN_MOD_LEN, "data is bigger than mod"},
363N/A{ PK11_R_DATA_TOO_LARGE_FOR_MODULUS, "data is too larger for mod"},
363N/A{ PK11_R_MISSING_KEY_COMPONENT, "a dsa component is missing"},
363N/A{ PK11_R_INVALID_SIGNATURE_LENGTH, "invalid signature length"},
363N/A{ PK11_R_INVALID_DSA_SIGNATURE_R, "missing r in dsa verify"},
363N/A{ PK11_R_INVALID_DSA_SIGNATURE_S, "missing s in dsa verify"},
363N/A{ PK11_R_INCONSISTENT_KEY, "inconsistent key type"},
363N/A{ PK11_R_ENCRYPTUPDATE, "C_EncryptUpdate failed"},
363N/A{ PK11_R_DECRYPTUPDATE, "C_DecryptUpdate failed"},
363N/A{ PK11_R_DIGESTINIT, "C_DigestInit failed"},
363N/A{ PK11_R_DIGESTUPDATE, "C_DigestUpdate failed"},
363N/A{ PK11_R_DIGESTFINAL, "C_DigestFinal failed"},
363N/A{ PK11_R_ENCRYPTFINAL, "C_EncryptFinal failed"},
363N/A{ PK11_R_DECRYPTFINAL, "C_DecryptFinal failed"},
363N/A{ PK11_R_NO_PRNG_SUPPORT, "Slot does not support PRNG"},
363N/A{ PK11_R_GETTOKENINFO, "C_GetTokenInfo failed"},
363N/A{ PK11_R_DERIVEKEY, "C_DeriveKey failed"},
363N/A{ PK11_R_GET_OPERATION_STATE, "C_GetOperationState failed"},
363N/A{ PK11_R_SET_OPERATION_STATE, "C_SetOperationState failed"},
363N/A{ PK11_R_INVALID_HANDLE, "invalid PKCS#11 object handle"},
363N/A{ PK11_R_KEY_OR_IV_LEN_PROBLEM, "IV or key length incorrect"},
363N/A{ PK11_R_INVALID_OPERATION_TYPE, "invalid operation type"},
363N/A{ PK11_R_ADD_NID_FAILED, "failed to add NID" },
363N/A{ PK11_R_ATFORK_FAILED, "atfork failed" },
363N/A{ PK11_R_TOKEN_LOGIN_FAILED, "C_Login failed on token" },
363N/A{ PK11_R_MORE_THAN_ONE_OBJECT_FOUND, "more than one object found" },
363N/A{ PK11_R_INVALID_PKCS11_URI, "pkcs11 URI provided is invalid" },
363N/A{ PK11_R_COULD_NOT_READ_PIN, "could not read PIN from terminal" },
363N/A{ PK11_R_PIN_NOT_READ_FROM_COMMAND, "PIN not read from external command" },
363N/A{ PK11_R_COULD_NOT_OPEN_COMMAND, "could not popen dialog command" },
363N/A{ PK11_R_PIPE_FAILED, "pipe failed" },
363N/A{ PK11_R_BAD_PASSPHRASE_SPEC, "bad passphrasedialog specification" },
363N/A{ PK11_R_TOKEN_NOT_INITIALIZED, "token not initialized" },
363N/A{ PK11_R_TOKEN_PIN_NOT_SET, "token PIN required but not set" },
363N/A{ PK11_R_TOKEN_PIN_NOT_PROVIDED, "token PIN required but not provided" },
363N/A{ PK11_R_MISSING_OBJECT_LABEL, "missing mandatory 'object' keyword" },
363N/A{ PK11_R_TOKEN_ATTRS_DO_NOT_MATCH, "token attrs provided do not match" },
363N/A{ PK11_R_PRIV_KEY_NOT_FOUND, "private key not found in keystore" },
363N/A{ PK11_R_NO_OBJECT_FOUND, "specified object not found" },
363N/A{ PK11_R_PIN_CACHING_POLICY_INVALID, "PIN set but caching policy invalid" },
363N/A{ PK11_R_SYSCONF_FAILED, "sysconf failed" },
363N/A{ PK11_R_MMAP_FAILED, "mmap failed" },
363N/A{ PK11_R_PRIV_PROC_LOCK_MEMORY_MISSING, "PROC_LOCK_MEMORY privilege missing" },
363N/A{ PK11_R_MLOCK_FAILED, "mlock failed" },
363N/A{ PK11_R_FORK_FAILED, "fork failed" },
363N/A{ 0, NULL}
363N/A};
363N/A#endif /* OPENSSL_NO_ERR */
363N/A
363N/Astatic int pk11_lib_error_code = 0;
363N/Astatic int pk11_error_init = 1;
363N/A
363N/A#ifdef PK11_ENGINE_LIB_NAME
363N/Astatic ERR_STRING_DATA pk11_engine_lib_name[] =
363N/A{
363N/A{0, PK11_ENGINE_LIB_NAME},
363N/A{0, NULL}
363N/A};
363N/A#endif
363N/A
363N/Astatic void
363N/AERR_load_pk11_strings(void)
363N/A {
363N/A if (pk11_lib_error_code == 0)
363N/A pk11_lib_error_code = ERR_get_next_error_library();
363N/A
363N/A if (pk11_error_init)
363N/A {
363N/A pk11_error_init = 0;
363N/A#ifndef OPENSSL_NO_ERR
363N/A ERR_load_strings(pk11_lib_error_code, pk11_str_functs);
363N/A ERR_load_strings(pk11_lib_error_code, pk11_str_reasons);
363N/A#endif
363N/A
363N/A#ifdef PK11_ENGINE_LIB_NAME
363N/A pk11_engine_lib_name->error =
363N/A ERR_PACK(pk11_lib_error_code, 0, 0);
363N/A ERR_load_strings(0, pk11_engine_lib_name);
363N/A#endif
363N/A }
363N/A}
363N/A
363N/Astatic void
363N/AERR_unload_pk11_strings(void)
363N/A {
363N/A if (pk11_error_init == 0)
363N/A {
363N/A#ifndef OPENSSL_NO_ERR
363N/A ERR_unload_strings(pk11_lib_error_code, pk11_str_functs);
363N/A ERR_unload_strings(pk11_lib_error_code, pk11_str_reasons);
363N/A#endif
363N/A
363N/A#ifdef PK11_ENGINE_LIB_NAME
363N/A ERR_unload_strings(0, pk11_engine_lib_name);
363N/A#endif
363N/A
363N/A pk11_error_init = 1;
363N/A }
363N/A}
363N/A
363N/Avoid
363N/AERR_pk11_error(int function, int reason, char *file, int line)
363N/A{
363N/A if (pk11_lib_error_code == 0)
363N/A pk11_lib_error_code = ERR_get_next_error_library();
363N/A ERR_PUT_error(pk11_lib_error_code, function, reason, file, line);
363N/A}
363N/A
363N/Avoid
363N/APK11err_add_data(int function, int reason, CK_RV rv)
363N/A{
363N/A char tmp_buf[20];
363N/A
363N/A PK11err(function, reason);
363N/A (void) snprintf(tmp_buf, sizeof (tmp_buf), "%lx", rv);
363N/A ERR_add_error_data(2, "PK11 CK_RV=0X", tmp_buf);
363N/A}