17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 2533f5ff17SMilan Jurik * Copyright 2012 Milan Jurik. All rights reserved. 26*b106467fSJason King * Copyright 2015 Jason King. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Block comment which describes the contents of this file. 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <stdio.h> 347c478bd9Sstevel@tonic-gate #include <security/cryptoki.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate /* 377c478bd9Sstevel@tonic-gate * pkcs11_strerror: returns a string representation of the given return code. 387c478bd9Sstevel@tonic-gate * The string returned is static pointer. It doesn't need to be free'd 397c478bd9Sstevel@tonic-gate * by the caller. 407c478bd9Sstevel@tonic-gate */ 417c478bd9Sstevel@tonic-gate char * pkcs11_strerror(CK_RV rv)427c478bd9Sstevel@tonic-gatepkcs11_strerror(CK_RV rv) 437c478bd9Sstevel@tonic-gate { 447c478bd9Sstevel@tonic-gate static char errstr[128]; 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate switch (rv) { 477c478bd9Sstevel@tonic-gate case CKR_OK: 487c478bd9Sstevel@tonic-gate return ("CKR_OK"); 497c478bd9Sstevel@tonic-gate case CKR_CANCEL: 507c478bd9Sstevel@tonic-gate return ("CKR_CANCEL"); 517c478bd9Sstevel@tonic-gate case CKR_HOST_MEMORY: 527c478bd9Sstevel@tonic-gate return ("CKR_HOST_MEMORY"); 537c478bd9Sstevel@tonic-gate case CKR_SLOT_ID_INVALID: 547c478bd9Sstevel@tonic-gate return ("CKR_SLOT_ID_INVALID"); 557c478bd9Sstevel@tonic-gate case CKR_GENERAL_ERROR: 567c478bd9Sstevel@tonic-gate return ("CKR_GENERAL_ERROR"); 577c478bd9Sstevel@tonic-gate case CKR_FUNCTION_FAILED: 587c478bd9Sstevel@tonic-gate return ("CKR_FUNCTION_FAILED"); 597c478bd9Sstevel@tonic-gate case CKR_ARGUMENTS_BAD: 607c478bd9Sstevel@tonic-gate return ("CKR_ARGUMENTS_BAD"); 617c478bd9Sstevel@tonic-gate case CKR_NO_EVENT: 627c478bd9Sstevel@tonic-gate return ("CKR_NO_EVENT"); 637c478bd9Sstevel@tonic-gate case CKR_NEED_TO_CREATE_THREADS: 647c478bd9Sstevel@tonic-gate return ("CKR_NEED_TO_CREATE_THREADS"); 657c478bd9Sstevel@tonic-gate case CKR_CANT_LOCK: 667c478bd9Sstevel@tonic-gate return ("CKR_CANT_LOCK"); 677c478bd9Sstevel@tonic-gate case CKR_ATTRIBUTE_READ_ONLY: 687c478bd9Sstevel@tonic-gate return ("CKR_ATTRIBUTE_READ_ONLY"); 697c478bd9Sstevel@tonic-gate case CKR_ATTRIBUTE_SENSITIVE: 707c478bd9Sstevel@tonic-gate return ("CKR_ATTRIBUTE_SENSITIVE"); 717c478bd9Sstevel@tonic-gate case CKR_ATTRIBUTE_TYPE_INVALID: 727c478bd9Sstevel@tonic-gate return ("CKR_ATTRIBUTE_TYPE_INVALID"); 737c478bd9Sstevel@tonic-gate case CKR_ATTRIBUTE_VALUE_INVALID: 747c478bd9Sstevel@tonic-gate return ("CKR_ATTRIBUTE_VALUE_INVALID"); 75*b106467fSJason King case CKR_ACTION_PROHIBITED: 76*b106467fSJason King return ("CKR_ACTION_PROHIBITED"); 777c478bd9Sstevel@tonic-gate case CKR_DATA_INVALID: 787c478bd9Sstevel@tonic-gate return ("CKR_DATA_INVALID"); 797c478bd9Sstevel@tonic-gate case CKR_DATA_LEN_RANGE: 807c478bd9Sstevel@tonic-gate return ("CKR_DATA_LEN_RANGE"); 817c478bd9Sstevel@tonic-gate case CKR_DEVICE_ERROR: 827c478bd9Sstevel@tonic-gate return ("CKR_DEVICE_ERROR"); 837c478bd9Sstevel@tonic-gate case CKR_DEVICE_MEMORY: 847c478bd9Sstevel@tonic-gate return ("CKR_DEVICE_MEMORY"); 857c478bd9Sstevel@tonic-gate case CKR_DEVICE_REMOVED: 867c478bd9Sstevel@tonic-gate return ("CKR_DEVICE_REMOVED"); 877c478bd9Sstevel@tonic-gate case CKR_ENCRYPTED_DATA_INVALID: 887c478bd9Sstevel@tonic-gate return ("CKR_ENCRYPTED_DATA_INVALID"); 897c478bd9Sstevel@tonic-gate case CKR_ENCRYPTED_DATA_LEN_RANGE: 907c478bd9Sstevel@tonic-gate return ("CKR_ENCRYPTED_DATA_LEN_RANGE"); 917c478bd9Sstevel@tonic-gate case CKR_FUNCTION_CANCELED: 927c478bd9Sstevel@tonic-gate return ("CKR_FUNCTION_CANCELED"); 937c478bd9Sstevel@tonic-gate case CKR_FUNCTION_NOT_PARALLEL: 947c478bd9Sstevel@tonic-gate return ("CKR_FUNCTION_NOT_PARALLEL"); 957c478bd9Sstevel@tonic-gate case CKR_FUNCTION_NOT_SUPPORTED: 967c478bd9Sstevel@tonic-gate return ("CKR_FUNCTION_NOT_SUPPORTED"); 977c478bd9Sstevel@tonic-gate case CKR_KEY_HANDLE_INVALID: 987c478bd9Sstevel@tonic-gate return ("CKR_KEY_HANDLE_INVALID"); 997c478bd9Sstevel@tonic-gate case CKR_KEY_SIZE_RANGE: 1007c478bd9Sstevel@tonic-gate return ("CKR_KEY_SIZE_RANGE"); 1017c478bd9Sstevel@tonic-gate case CKR_KEY_TYPE_INCONSISTENT: 1027c478bd9Sstevel@tonic-gate return ("CKR_KEY_TYPE_INCONSISTENT"); 1037c478bd9Sstevel@tonic-gate case CKR_KEY_NOT_NEEDED: 1047c478bd9Sstevel@tonic-gate return ("CKR_KEY_NOT_NEEDED"); 1057c478bd9Sstevel@tonic-gate case CKR_KEY_CHANGED: 1067c478bd9Sstevel@tonic-gate return ("CKR_KEY_CHANGED"); 1077c478bd9Sstevel@tonic-gate case CKR_KEY_NEEDED: 1087c478bd9Sstevel@tonic-gate return ("CKR_KEY_NEEDED"); 1097c478bd9Sstevel@tonic-gate case CKR_KEY_INDIGESTIBLE: 1107c478bd9Sstevel@tonic-gate return ("CKR_KEY_INDIGESTIBLE"); 1117c478bd9Sstevel@tonic-gate case CKR_KEY_FUNCTION_NOT_PERMITTED: 1127c478bd9Sstevel@tonic-gate return ("CKR_KEY_FUNCTION_NOT_PERMITTED"); 1137c478bd9Sstevel@tonic-gate case CKR_KEY_NOT_WRAPPABLE: 1147c478bd9Sstevel@tonic-gate return ("CKR_KEY_NOT_WRAPPABLE"); 1157c478bd9Sstevel@tonic-gate case CKR_KEY_UNEXTRACTABLE: 1167c478bd9Sstevel@tonic-gate return ("CKR_KEY_UNEXTRACTABLE"); 1177c478bd9Sstevel@tonic-gate case CKR_MECHANISM_INVALID: 1187c478bd9Sstevel@tonic-gate return ("CKR_MECHANISM_INVALID"); 1197c478bd9Sstevel@tonic-gate case CKR_MECHANISM_PARAM_INVALID: 1207c478bd9Sstevel@tonic-gate return ("CKR_MECHANISM_PARAM_INVALID"); 1217c478bd9Sstevel@tonic-gate case CKR_OBJECT_HANDLE_INVALID: 1227c478bd9Sstevel@tonic-gate return ("CKR_OBJECT_HANDLE_INVALID"); 1237c478bd9Sstevel@tonic-gate case CKR_OPERATION_ACTIVE: 1247c478bd9Sstevel@tonic-gate return ("CKR_OPERATION_ACTIVE"); 1257c478bd9Sstevel@tonic-gate case CKR_OPERATION_NOT_INITIALIZED: 1267c478bd9Sstevel@tonic-gate return ("CKR_OPERATION_NOT_INITIALIZED"); 1277c478bd9Sstevel@tonic-gate case CKR_PIN_INCORRECT: 1287c478bd9Sstevel@tonic-gate return ("CKR_PIN_INCORRECT"); 1297c478bd9Sstevel@tonic-gate case CKR_PIN_INVALID: 1307c478bd9Sstevel@tonic-gate return ("CKR_PIN_INVALID"); 1317c478bd9Sstevel@tonic-gate case CKR_PIN_LEN_RANGE: 1327c478bd9Sstevel@tonic-gate return ("CKR_PIN_LEN_RANGE"); 1337c478bd9Sstevel@tonic-gate case CKR_PIN_EXPIRED: 1347c478bd9Sstevel@tonic-gate return ("CKR_PIN_EXPIRED"); 1357c478bd9Sstevel@tonic-gate case CKR_PIN_LOCKED: 1367c478bd9Sstevel@tonic-gate return ("CKR_PIN_LOCKED"); 1377c478bd9Sstevel@tonic-gate case CKR_SESSION_CLOSED: 1387c478bd9Sstevel@tonic-gate return ("CKR_SESSION_CLOSED"); 1397c478bd9Sstevel@tonic-gate case CKR_SESSION_COUNT: 1407c478bd9Sstevel@tonic-gate return ("CKR_SESSION_COUNT"); 1417c478bd9Sstevel@tonic-gate case CKR_SESSION_HANDLE_INVALID: 1427c478bd9Sstevel@tonic-gate return ("CKR_SESSION_HANDLE_INVALID"); 1437c478bd9Sstevel@tonic-gate case CKR_SESSION_PARALLEL_NOT_SUPPORTED: 1447c478bd9Sstevel@tonic-gate return ("CKR_SESSION_PARALLEL_NOT_SUPPORTED"); 1457c478bd9Sstevel@tonic-gate case CKR_SESSION_READ_ONLY: 1467c478bd9Sstevel@tonic-gate return ("CKR_SESSION_READ_ONLY"); 1477c478bd9Sstevel@tonic-gate case CKR_SESSION_EXISTS: 1487c478bd9Sstevel@tonic-gate return ("CKR_SESSION_EXISTS"); 1497c478bd9Sstevel@tonic-gate case CKR_SESSION_READ_ONLY_EXISTS: 1507c478bd9Sstevel@tonic-gate return ("CKR_SESSION_READ_ONLY_EXISTS"); 1517c478bd9Sstevel@tonic-gate case CKR_SESSION_READ_WRITE_SO_EXISTS: 1527c478bd9Sstevel@tonic-gate return ("CKR_SESSION_READ_WRITE_SO_EXISTS"); 1537c478bd9Sstevel@tonic-gate case CKR_SIGNATURE_INVALID: 1547c478bd9Sstevel@tonic-gate return ("CKR_SIGNATURE_INVALID"); 1557c478bd9Sstevel@tonic-gate case CKR_SIGNATURE_LEN_RANGE: 1567c478bd9Sstevel@tonic-gate return ("CKR_SIGNATURE_LEN_RANGE"); 1577c478bd9Sstevel@tonic-gate case CKR_TEMPLATE_INCOMPLETE: 1587c478bd9Sstevel@tonic-gate return ("CKR_TEMPLATE_INCOMPLETE"); 1597c478bd9Sstevel@tonic-gate case CKR_TEMPLATE_INCONSISTENT: 1607c478bd9Sstevel@tonic-gate return ("CKR_TEMPLATE_INCONSISTENT"); 1617c478bd9Sstevel@tonic-gate case CKR_TOKEN_NOT_PRESENT: 1627c478bd9Sstevel@tonic-gate return ("CKR_TOKEN_NOT_PRESENT"); 1637c478bd9Sstevel@tonic-gate case CKR_TOKEN_NOT_RECOGNIZED: 1647c478bd9Sstevel@tonic-gate return ("CKR_TOKEN_NOT_RECOGNIZED"); 1657c478bd9Sstevel@tonic-gate case CKR_TOKEN_WRITE_PROTECTED: 1667c478bd9Sstevel@tonic-gate return ("CKR_TOKEN_WRITE_PROTECTED"); 1677c478bd9Sstevel@tonic-gate case CKR_UNWRAPPING_KEY_HANDLE_INVALID: 1687c478bd9Sstevel@tonic-gate return ("CKR_UNWRAPPING_KEY_HANDLE_INVALID"); 1697c478bd9Sstevel@tonic-gate case CKR_UNWRAPPING_KEY_SIZE_RANGE: 1707c478bd9Sstevel@tonic-gate return ("CKR_UNWRAPPING_KEY_SIZE_RANGE"); 1717c478bd9Sstevel@tonic-gate case CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT: 1727c478bd9Sstevel@tonic-gate return ("CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT"); 1737c478bd9Sstevel@tonic-gate case CKR_USER_ALREADY_LOGGED_IN: 1747c478bd9Sstevel@tonic-gate return ("CKR_USER_ALREADY_LOGGED_IN"); 1757c478bd9Sstevel@tonic-gate case CKR_USER_NOT_LOGGED_IN: 1767c478bd9Sstevel@tonic-gate return ("CKR_USER_NOT_LOGGED_IN"); 1777c478bd9Sstevel@tonic-gate case CKR_USER_PIN_NOT_INITIALIZED: 1787c478bd9Sstevel@tonic-gate return ("CKR_USER_PIN_NOT_INITIALIZED"); 1797c478bd9Sstevel@tonic-gate case CKR_USER_TYPE_INVALID: 1807c478bd9Sstevel@tonic-gate return ("CKR_USER_TYPE_INVALID"); 1817c478bd9Sstevel@tonic-gate case CKR_USER_ANOTHER_ALREADY_LOGGED_IN: 1827c478bd9Sstevel@tonic-gate return ("CKR_USER_ANOTHER_ALREADY_LOGGED_IN"); 1837c478bd9Sstevel@tonic-gate case CKR_USER_TOO_MANY_TYPES: 1847c478bd9Sstevel@tonic-gate return ("CKR_USER_TOO_MANY_TYPES"); 1857c478bd9Sstevel@tonic-gate case CKR_WRAPPED_KEY_INVALID: 1867c478bd9Sstevel@tonic-gate return ("CKR_WRAPPED_KEY_INVALID"); 1877c478bd9Sstevel@tonic-gate case CKR_WRAPPED_KEY_LEN_RANGE: 1887c478bd9Sstevel@tonic-gate return ("CKR_WRAPPED_KEY_LEN_RANGE"); 1897c478bd9Sstevel@tonic-gate case CKR_WRAPPING_KEY_HANDLE_INVALID: 1907c478bd9Sstevel@tonic-gate return ("CKR_WRAPPING_KEY_HANDLE_INVALID"); 1917c478bd9Sstevel@tonic-gate case CKR_WRAPPING_KEY_SIZE_RANGE: 1927c478bd9Sstevel@tonic-gate return ("CKR_WRAPPING_KEY_SIZE_RANGE"); 1937c478bd9Sstevel@tonic-gate case CKR_WRAPPING_KEY_TYPE_INCONSISTENT: 1947c478bd9Sstevel@tonic-gate return ("CKR_WRAPPING_KEY_TYPE_INCONSISTENT"); 1957c478bd9Sstevel@tonic-gate case CKR_RANDOM_SEED_NOT_SUPPORTED: 1967c478bd9Sstevel@tonic-gate return ("CKR_RANDOM_SEED_NOT_SUPPORTED"); 1977c478bd9Sstevel@tonic-gate case CKR_RANDOM_NO_RNG: 1987c478bd9Sstevel@tonic-gate return ("CKR_RANDOM_NO_RNG"); 1997c478bd9Sstevel@tonic-gate case CKR_DOMAIN_PARAMS_INVALID: 2007c478bd9Sstevel@tonic-gate return ("CKR_DOMAIN_PARAMS_INVALID"); 201*b106467fSJason King case CKR_CURVE_NOT_SUPPORTED: 202*b106467fSJason King return ("CLR_CURVE_NOT_SUPPORTED"); 2037c478bd9Sstevel@tonic-gate case CKR_BUFFER_TOO_SMALL: 2047c478bd9Sstevel@tonic-gate return ("CKR_BUFFER_TOO_SMALL"); 2057c478bd9Sstevel@tonic-gate case CKR_SAVED_STATE_INVALID: 2067c478bd9Sstevel@tonic-gate return ("CKR_SAVED_STATE_INVALID"); 2077c478bd9Sstevel@tonic-gate case CKR_INFORMATION_SENSITIVE: 2087c478bd9Sstevel@tonic-gate return ("CKR_INFORMATION_SENSITIVE"); 2097c478bd9Sstevel@tonic-gate case CKR_STATE_UNSAVEABLE: 2107c478bd9Sstevel@tonic-gate return ("CKR_STATE_UNSAVEABLE"); 2117c478bd9Sstevel@tonic-gate case CKR_CRYPTOKI_NOT_INITIALIZED: 2127c478bd9Sstevel@tonic-gate return ("CKR_CRYPTOKI_NOT_INITIALIZED"); 2137c478bd9Sstevel@tonic-gate case CKR_CRYPTOKI_ALREADY_INITIALIZED: 2147c478bd9Sstevel@tonic-gate return ("CKR_CRYPTOKI_ALREADY_INITIALIZED"); 2157c478bd9Sstevel@tonic-gate case CKR_MUTEX_BAD: 2167c478bd9Sstevel@tonic-gate return ("CKR_MUTEX_BAD"); 2177c478bd9Sstevel@tonic-gate case CKR_MUTEX_NOT_LOCKED: 2187c478bd9Sstevel@tonic-gate return ("CKR_MUTEX_NOT_LOCKED"); 219*b106467fSJason King case CKR_NEW_PIN_MODE: 220*b106467fSJason King return ("CKR_NEW_PIN_MODE"); 221*b106467fSJason King case CKR_NEXT_OTP: 222*b106467fSJason King return ("CKR_NEXT_OTP"); 223*b106467fSJason King case CKR_EXCEEDED_MAX_ITERATIONS: 224*b106467fSJason King return ("CKR_EXCEEDED_MAX_ITERATIONS"); 225*b106467fSJason King case CKR_FIPS_SELF_TEST_FAILED: 226*b106467fSJason King return ("CKR_FIPS_SELF_TEST_FAILED"); 227*b106467fSJason King case CKR_LIBRARY_LOAD_FAILED: 228*b106467fSJason King return ("CKR_LIBRARY_LOAD_FAILED"); 229*b106467fSJason King case CKR_PIN_TOO_WEAK: 230*b106467fSJason King return ("CKR_PIN_TOO_WEAK"); 231*b106467fSJason King case CKR_PUBLIC_KEY_INVALID: 232*b106467fSJason King return ("CKR_PUBLIC_KEY_INVALID"); 233*b106467fSJason King case CKR_FUNCTION_REJECTED: 234*b106467fSJason King return ("CKR_FUNCTION_REJECTED"); 2357c478bd9Sstevel@tonic-gate case CKR_VENDOR_DEFINED: 2367c478bd9Sstevel@tonic-gate return ("CKR_VENDOR_DEFINED"); 2377c478bd9Sstevel@tonic-gate default: 2387c478bd9Sstevel@tonic-gate /* rv not found */ 2397c478bd9Sstevel@tonic-gate (void) snprintf(errstr, sizeof (errstr), 2407c478bd9Sstevel@tonic-gate "Unknown return code: 0x%lx", rv); 2417c478bd9Sstevel@tonic-gate return (errstr); 2427c478bd9Sstevel@tonic-gate } 2437c478bd9Sstevel@tonic-gate } 244