1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * Copyright 2012 Milan Jurik. All rights reserved. 26 */ 27 28 /* 29 * Block comment which describes the contents of this file. 30 */ 31 32 #include <stdio.h> 33 #include <security/cryptoki.h> 34 35 /* 36 * pkcs11_strerror: returns a string representation of the given return code. 37 * The string returned is static pointer. It doesn't need to be free'd 38 * by the caller. 39 */ 40 char * pkcs11_strerror(CK_RV rv)41pkcs11_strerror(CK_RV rv) 42 { 43 static char errstr[128]; 44 45 switch (rv) { 46 case CKR_OK: 47 return ("CKR_OK"); 48 case CKR_CANCEL: 49 return ("CKR_CANCEL"); 50 case CKR_HOST_MEMORY: 51 return ("CKR_HOST_MEMORY"); 52 case CKR_SLOT_ID_INVALID: 53 return ("CKR_SLOT_ID_INVALID"); 54 case CKR_GENERAL_ERROR: 55 return ("CKR_GENERAL_ERROR"); 56 case CKR_FUNCTION_FAILED: 57 return ("CKR_FUNCTION_FAILED"); 58 case CKR_ARGUMENTS_BAD: 59 return ("CKR_ARGUMENTS_BAD"); 60 case CKR_NO_EVENT: 61 return ("CKR_NO_EVENT"); 62 case CKR_NEED_TO_CREATE_THREADS: 63 return ("CKR_NEED_TO_CREATE_THREADS"); 64 case CKR_CANT_LOCK: 65 return ("CKR_CANT_LOCK"); 66 case CKR_ATTRIBUTE_READ_ONLY: 67 return ("CKR_ATTRIBUTE_READ_ONLY"); 68 case CKR_ATTRIBUTE_SENSITIVE: 69 return ("CKR_ATTRIBUTE_SENSITIVE"); 70 case CKR_ATTRIBUTE_TYPE_INVALID: 71 return ("CKR_ATTRIBUTE_TYPE_INVALID"); 72 case CKR_ATTRIBUTE_VALUE_INVALID: 73 return ("CKR_ATTRIBUTE_VALUE_INVALID"); 74 case CKR_DATA_INVALID: 75 return ("CKR_DATA_INVALID"); 76 case CKR_DATA_LEN_RANGE: 77 return ("CKR_DATA_LEN_RANGE"); 78 case CKR_DEVICE_ERROR: 79 return ("CKR_DEVICE_ERROR"); 80 case CKR_DEVICE_MEMORY: 81 return ("CKR_DEVICE_MEMORY"); 82 case CKR_DEVICE_REMOVED: 83 return ("CKR_DEVICE_REMOVED"); 84 case CKR_ENCRYPTED_DATA_INVALID: 85 return ("CKR_ENCRYPTED_DATA_INVALID"); 86 case CKR_ENCRYPTED_DATA_LEN_RANGE: 87 return ("CKR_ENCRYPTED_DATA_LEN_RANGE"); 88 case CKR_FUNCTION_CANCELED: 89 return ("CKR_FUNCTION_CANCELED"); 90 case CKR_FUNCTION_NOT_PARALLEL: 91 return ("CKR_FUNCTION_NOT_PARALLEL"); 92 case CKR_FUNCTION_NOT_SUPPORTED: 93 return ("CKR_FUNCTION_NOT_SUPPORTED"); 94 case CKR_KEY_HANDLE_INVALID: 95 return ("CKR_KEY_HANDLE_INVALID"); 96 case CKR_KEY_SIZE_RANGE: 97 return ("CKR_KEY_SIZE_RANGE"); 98 case CKR_KEY_TYPE_INCONSISTENT: 99 return ("CKR_KEY_TYPE_INCONSISTENT"); 100 case CKR_KEY_NOT_NEEDED: 101 return ("CKR_KEY_NOT_NEEDED"); 102 case CKR_KEY_CHANGED: 103 return ("CKR_KEY_CHANGED"); 104 case CKR_KEY_NEEDED: 105 return ("CKR_KEY_NEEDED"); 106 case CKR_KEY_INDIGESTIBLE: 107 return ("CKR_KEY_INDIGESTIBLE"); 108 case CKR_KEY_FUNCTION_NOT_PERMITTED: 109 return ("CKR_KEY_FUNCTION_NOT_PERMITTED"); 110 case CKR_KEY_NOT_WRAPPABLE: 111 return ("CKR_KEY_NOT_WRAPPABLE"); 112 case CKR_KEY_UNEXTRACTABLE: 113 return ("CKR_KEY_UNEXTRACTABLE"); 114 case CKR_MECHANISM_INVALID: 115 return ("CKR_MECHANISM_INVALID"); 116 case CKR_MECHANISM_PARAM_INVALID: 117 return ("CKR_MECHANISM_PARAM_INVALID"); 118 case CKR_OBJECT_HANDLE_INVALID: 119 return ("CKR_OBJECT_HANDLE_INVALID"); 120 case CKR_OPERATION_ACTIVE: 121 return ("CKR_OPERATION_ACTIVE"); 122 case CKR_OPERATION_NOT_INITIALIZED: 123 return ("CKR_OPERATION_NOT_INITIALIZED"); 124 case CKR_PIN_INCORRECT: 125 return ("CKR_PIN_INCORRECT"); 126 case CKR_PIN_INVALID: 127 return ("CKR_PIN_INVALID"); 128 case CKR_PIN_LEN_RANGE: 129 return ("CKR_PIN_LEN_RANGE"); 130 case CKR_PIN_EXPIRED: 131 return ("CKR_PIN_EXPIRED"); 132 case CKR_PIN_LOCKED: 133 return ("CKR_PIN_LOCKED"); 134 case CKR_SESSION_CLOSED: 135 return ("CKR_SESSION_CLOSED"); 136 case CKR_SESSION_COUNT: 137 return ("CKR_SESSION_COUNT"); 138 case CKR_SESSION_HANDLE_INVALID: 139 return ("CKR_SESSION_HANDLE_INVALID"); 140 case CKR_SESSION_PARALLEL_NOT_SUPPORTED: 141 return ("CKR_SESSION_PARALLEL_NOT_SUPPORTED"); 142 case CKR_SESSION_READ_ONLY: 143 return ("CKR_SESSION_READ_ONLY"); 144 case CKR_SESSION_EXISTS: 145 return ("CKR_SESSION_EXISTS"); 146 case CKR_SESSION_READ_ONLY_EXISTS: 147 return ("CKR_SESSION_READ_ONLY_EXISTS"); 148 case CKR_SESSION_READ_WRITE_SO_EXISTS: 149 return ("CKR_SESSION_READ_WRITE_SO_EXISTS"); 150 case CKR_SIGNATURE_INVALID: 151 return ("CKR_SIGNATURE_INVALID"); 152 case CKR_SIGNATURE_LEN_RANGE: 153 return ("CKR_SIGNATURE_LEN_RANGE"); 154 case CKR_TEMPLATE_INCOMPLETE: 155 return ("CKR_TEMPLATE_INCOMPLETE"); 156 case CKR_TEMPLATE_INCONSISTENT: 157 return ("CKR_TEMPLATE_INCONSISTENT"); 158 case CKR_TOKEN_NOT_PRESENT: 159 return ("CKR_TOKEN_NOT_PRESENT"); 160 case CKR_TOKEN_NOT_RECOGNIZED: 161 return ("CKR_TOKEN_NOT_RECOGNIZED"); 162 case CKR_TOKEN_WRITE_PROTECTED: 163 return ("CKR_TOKEN_WRITE_PROTECTED"); 164 case CKR_UNWRAPPING_KEY_HANDLE_INVALID: 165 return ("CKR_UNWRAPPING_KEY_HANDLE_INVALID"); 166 case CKR_UNWRAPPING_KEY_SIZE_RANGE: 167 return ("CKR_UNWRAPPING_KEY_SIZE_RANGE"); 168 case CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT: 169 return ("CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT"); 170 case CKR_USER_ALREADY_LOGGED_IN: 171 return ("CKR_USER_ALREADY_LOGGED_IN"); 172 case CKR_USER_NOT_LOGGED_IN: 173 return ("CKR_USER_NOT_LOGGED_IN"); 174 case CKR_USER_PIN_NOT_INITIALIZED: 175 return ("CKR_USER_PIN_NOT_INITIALIZED"); 176 case CKR_USER_TYPE_INVALID: 177 return ("CKR_USER_TYPE_INVALID"); 178 case CKR_USER_ANOTHER_ALREADY_LOGGED_IN: 179 return ("CKR_USER_ANOTHER_ALREADY_LOGGED_IN"); 180 case CKR_USER_TOO_MANY_TYPES: 181 return ("CKR_USER_TOO_MANY_TYPES"); 182 case CKR_WRAPPED_KEY_INVALID: 183 return ("CKR_WRAPPED_KEY_INVALID"); 184 case CKR_WRAPPED_KEY_LEN_RANGE: 185 return ("CKR_WRAPPED_KEY_LEN_RANGE"); 186 case CKR_WRAPPING_KEY_HANDLE_INVALID: 187 return ("CKR_WRAPPING_KEY_HANDLE_INVALID"); 188 case CKR_WRAPPING_KEY_SIZE_RANGE: 189 return ("CKR_WRAPPING_KEY_SIZE_RANGE"); 190 case CKR_WRAPPING_KEY_TYPE_INCONSISTENT: 191 return ("CKR_WRAPPING_KEY_TYPE_INCONSISTENT"); 192 case CKR_RANDOM_SEED_NOT_SUPPORTED: 193 return ("CKR_RANDOM_SEED_NOT_SUPPORTED"); 194 case CKR_RANDOM_NO_RNG: 195 return ("CKR_RANDOM_NO_RNG"); 196 case CKR_DOMAIN_PARAMS_INVALID: 197 return ("CKR_DOMAIN_PARAMS_INVALID"); 198 case CKR_BUFFER_TOO_SMALL: 199 return ("CKR_BUFFER_TOO_SMALL"); 200 case CKR_SAVED_STATE_INVALID: 201 return ("CKR_SAVED_STATE_INVALID"); 202 case CKR_INFORMATION_SENSITIVE: 203 return ("CKR_INFORMATION_SENSITIVE"); 204 case CKR_STATE_UNSAVEABLE: 205 return ("CKR_STATE_UNSAVEABLE"); 206 case CKR_CRYPTOKI_NOT_INITIALIZED: 207 return ("CKR_CRYPTOKI_NOT_INITIALIZED"); 208 case CKR_CRYPTOKI_ALREADY_INITIALIZED: 209 return ("CKR_CRYPTOKI_ALREADY_INITIALIZED"); 210 case CKR_MUTEX_BAD: 211 return ("CKR_MUTEX_BAD"); 212 case CKR_MUTEX_NOT_LOCKED: 213 return ("CKR_MUTEX_NOT_LOCKED"); 214 case CKR_VENDOR_DEFINED: 215 return ("CKR_VENDOR_DEFINED"); 216 default: 217 /* rv not found */ 218 (void) snprintf(errstr, sizeof (errstr), 219 "Unknown return code: 0x%lx", rv); 220 return (errstr); 221 } 222 } 223