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. 25*33f5ff17SMilan Jurik * Copyright 2012 Milan Jurik. All rights reserved. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * Block comment which describes the contents of this file. 307c478bd9Sstevel@tonic-gate */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <stdio.h> 337c478bd9Sstevel@tonic-gate #include <security/cryptoki.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate /* 367c478bd9Sstevel@tonic-gate * pkcs11_strerror: returns a string representation of the given return code. 377c478bd9Sstevel@tonic-gate * The string returned is static pointer. It doesn't need to be free'd 387c478bd9Sstevel@tonic-gate * by the caller. 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate char * 417c478bd9Sstevel@tonic-gate pkcs11_strerror(CK_RV rv) 427c478bd9Sstevel@tonic-gate { 437c478bd9Sstevel@tonic-gate static char errstr[128]; 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate switch (rv) { 467c478bd9Sstevel@tonic-gate case CKR_OK: 477c478bd9Sstevel@tonic-gate return ("CKR_OK"); 487c478bd9Sstevel@tonic-gate case CKR_CANCEL: 497c478bd9Sstevel@tonic-gate return ("CKR_CANCEL"); 507c478bd9Sstevel@tonic-gate case CKR_HOST_MEMORY: 517c478bd9Sstevel@tonic-gate return ("CKR_HOST_MEMORY"); 527c478bd9Sstevel@tonic-gate case CKR_SLOT_ID_INVALID: 537c478bd9Sstevel@tonic-gate return ("CKR_SLOT_ID_INVALID"); 547c478bd9Sstevel@tonic-gate case CKR_GENERAL_ERROR: 557c478bd9Sstevel@tonic-gate return ("CKR_GENERAL_ERROR"); 567c478bd9Sstevel@tonic-gate case CKR_FUNCTION_FAILED: 577c478bd9Sstevel@tonic-gate return ("CKR_FUNCTION_FAILED"); 587c478bd9Sstevel@tonic-gate case CKR_ARGUMENTS_BAD: 597c478bd9Sstevel@tonic-gate return ("CKR_ARGUMENTS_BAD"); 607c478bd9Sstevel@tonic-gate case CKR_NO_EVENT: 617c478bd9Sstevel@tonic-gate return ("CKR_NO_EVENT"); 627c478bd9Sstevel@tonic-gate case CKR_NEED_TO_CREATE_THREADS: 637c478bd9Sstevel@tonic-gate return ("CKR_NEED_TO_CREATE_THREADS"); 647c478bd9Sstevel@tonic-gate case CKR_CANT_LOCK: 657c478bd9Sstevel@tonic-gate return ("CKR_CANT_LOCK"); 667c478bd9Sstevel@tonic-gate case CKR_ATTRIBUTE_READ_ONLY: 677c478bd9Sstevel@tonic-gate return ("CKR_ATTRIBUTE_READ_ONLY"); 687c478bd9Sstevel@tonic-gate case CKR_ATTRIBUTE_SENSITIVE: 697c478bd9Sstevel@tonic-gate return ("CKR_ATTRIBUTE_SENSITIVE"); 707c478bd9Sstevel@tonic-gate case CKR_ATTRIBUTE_TYPE_INVALID: 717c478bd9Sstevel@tonic-gate return ("CKR_ATTRIBUTE_TYPE_INVALID"); 727c478bd9Sstevel@tonic-gate case CKR_ATTRIBUTE_VALUE_INVALID: 737c478bd9Sstevel@tonic-gate return ("CKR_ATTRIBUTE_VALUE_INVALID"); 747c478bd9Sstevel@tonic-gate case CKR_DATA_INVALID: 757c478bd9Sstevel@tonic-gate return ("CKR_DATA_INVALID"); 767c478bd9Sstevel@tonic-gate case CKR_DATA_LEN_RANGE: 777c478bd9Sstevel@tonic-gate return ("CKR_DATA_LEN_RANGE"); 787c478bd9Sstevel@tonic-gate case CKR_DEVICE_ERROR: 797c478bd9Sstevel@tonic-gate return ("CKR_DEVICE_ERROR"); 807c478bd9Sstevel@tonic-gate case CKR_DEVICE_MEMORY: 817c478bd9Sstevel@tonic-gate return ("CKR_DEVICE_MEMORY"); 827c478bd9Sstevel@tonic-gate case CKR_DEVICE_REMOVED: 837c478bd9Sstevel@tonic-gate return ("CKR_DEVICE_REMOVED"); 847c478bd9Sstevel@tonic-gate case CKR_ENCRYPTED_DATA_INVALID: 857c478bd9Sstevel@tonic-gate return ("CKR_ENCRYPTED_DATA_INVALID"); 867c478bd9Sstevel@tonic-gate case CKR_ENCRYPTED_DATA_LEN_RANGE: 877c478bd9Sstevel@tonic-gate return ("CKR_ENCRYPTED_DATA_LEN_RANGE"); 887c478bd9Sstevel@tonic-gate case CKR_FUNCTION_CANCELED: 897c478bd9Sstevel@tonic-gate return ("CKR_FUNCTION_CANCELED"); 907c478bd9Sstevel@tonic-gate case CKR_FUNCTION_NOT_PARALLEL: 917c478bd9Sstevel@tonic-gate return ("CKR_FUNCTION_NOT_PARALLEL"); 927c478bd9Sstevel@tonic-gate case CKR_FUNCTION_NOT_SUPPORTED: 937c478bd9Sstevel@tonic-gate return ("CKR_FUNCTION_NOT_SUPPORTED"); 947c478bd9Sstevel@tonic-gate case CKR_KEY_HANDLE_INVALID: 957c478bd9Sstevel@tonic-gate return ("CKR_KEY_HANDLE_INVALID"); 967c478bd9Sstevel@tonic-gate case CKR_KEY_SIZE_RANGE: 977c478bd9Sstevel@tonic-gate return ("CKR_KEY_SIZE_RANGE"); 987c478bd9Sstevel@tonic-gate case CKR_KEY_TYPE_INCONSISTENT: 997c478bd9Sstevel@tonic-gate return ("CKR_KEY_TYPE_INCONSISTENT"); 1007c478bd9Sstevel@tonic-gate case CKR_KEY_NOT_NEEDED: 1017c478bd9Sstevel@tonic-gate return ("CKR_KEY_NOT_NEEDED"); 1027c478bd9Sstevel@tonic-gate case CKR_KEY_CHANGED: 1037c478bd9Sstevel@tonic-gate return ("CKR_KEY_CHANGED"); 1047c478bd9Sstevel@tonic-gate case CKR_KEY_NEEDED: 1057c478bd9Sstevel@tonic-gate return ("CKR_KEY_NEEDED"); 1067c478bd9Sstevel@tonic-gate case CKR_KEY_INDIGESTIBLE: 1077c478bd9Sstevel@tonic-gate return ("CKR_KEY_INDIGESTIBLE"); 1087c478bd9Sstevel@tonic-gate case CKR_KEY_FUNCTION_NOT_PERMITTED: 1097c478bd9Sstevel@tonic-gate return ("CKR_KEY_FUNCTION_NOT_PERMITTED"); 1107c478bd9Sstevel@tonic-gate case CKR_KEY_NOT_WRAPPABLE: 1117c478bd9Sstevel@tonic-gate return ("CKR_KEY_NOT_WRAPPABLE"); 1127c478bd9Sstevel@tonic-gate case CKR_KEY_UNEXTRACTABLE: 1137c478bd9Sstevel@tonic-gate return ("CKR_KEY_UNEXTRACTABLE"); 1147c478bd9Sstevel@tonic-gate case CKR_MECHANISM_INVALID: 1157c478bd9Sstevel@tonic-gate return ("CKR_MECHANISM_INVALID"); 1167c478bd9Sstevel@tonic-gate case CKR_MECHANISM_PARAM_INVALID: 1177c478bd9Sstevel@tonic-gate return ("CKR_MECHANISM_PARAM_INVALID"); 1187c478bd9Sstevel@tonic-gate case CKR_OBJECT_HANDLE_INVALID: 1197c478bd9Sstevel@tonic-gate return ("CKR_OBJECT_HANDLE_INVALID"); 1207c478bd9Sstevel@tonic-gate case CKR_OPERATION_ACTIVE: 1217c478bd9Sstevel@tonic-gate return ("CKR_OPERATION_ACTIVE"); 1227c478bd9Sstevel@tonic-gate case CKR_OPERATION_NOT_INITIALIZED: 1237c478bd9Sstevel@tonic-gate return ("CKR_OPERATION_NOT_INITIALIZED"); 1247c478bd9Sstevel@tonic-gate case CKR_PIN_INCORRECT: 1257c478bd9Sstevel@tonic-gate return ("CKR_PIN_INCORRECT"); 1267c478bd9Sstevel@tonic-gate case CKR_PIN_INVALID: 1277c478bd9Sstevel@tonic-gate return ("CKR_PIN_INVALID"); 1287c478bd9Sstevel@tonic-gate case CKR_PIN_LEN_RANGE: 1297c478bd9Sstevel@tonic-gate return ("CKR_PIN_LEN_RANGE"); 1307c478bd9Sstevel@tonic-gate case CKR_PIN_EXPIRED: 1317c478bd9Sstevel@tonic-gate return ("CKR_PIN_EXPIRED"); 1327c478bd9Sstevel@tonic-gate case CKR_PIN_LOCKED: 1337c478bd9Sstevel@tonic-gate return ("CKR_PIN_LOCKED"); 1347c478bd9Sstevel@tonic-gate case CKR_SESSION_CLOSED: 1357c478bd9Sstevel@tonic-gate return ("CKR_SESSION_CLOSED"); 1367c478bd9Sstevel@tonic-gate case CKR_SESSION_COUNT: 1377c478bd9Sstevel@tonic-gate return ("CKR_SESSION_COUNT"); 1387c478bd9Sstevel@tonic-gate case CKR_SESSION_HANDLE_INVALID: 1397c478bd9Sstevel@tonic-gate return ("CKR_SESSION_HANDLE_INVALID"); 1407c478bd9Sstevel@tonic-gate case CKR_SESSION_PARALLEL_NOT_SUPPORTED: 1417c478bd9Sstevel@tonic-gate return ("CKR_SESSION_PARALLEL_NOT_SUPPORTED"); 1427c478bd9Sstevel@tonic-gate case CKR_SESSION_READ_ONLY: 1437c478bd9Sstevel@tonic-gate return ("CKR_SESSION_READ_ONLY"); 1447c478bd9Sstevel@tonic-gate case CKR_SESSION_EXISTS: 1457c478bd9Sstevel@tonic-gate return ("CKR_SESSION_EXISTS"); 1467c478bd9Sstevel@tonic-gate case CKR_SESSION_READ_ONLY_EXISTS: 1477c478bd9Sstevel@tonic-gate return ("CKR_SESSION_READ_ONLY_EXISTS"); 1487c478bd9Sstevel@tonic-gate case CKR_SESSION_READ_WRITE_SO_EXISTS: 1497c478bd9Sstevel@tonic-gate return ("CKR_SESSION_READ_WRITE_SO_EXISTS"); 1507c478bd9Sstevel@tonic-gate case CKR_SIGNATURE_INVALID: 1517c478bd9Sstevel@tonic-gate return ("CKR_SIGNATURE_INVALID"); 1527c478bd9Sstevel@tonic-gate case CKR_SIGNATURE_LEN_RANGE: 1537c478bd9Sstevel@tonic-gate return ("CKR_SIGNATURE_LEN_RANGE"); 1547c478bd9Sstevel@tonic-gate case CKR_TEMPLATE_INCOMPLETE: 1557c478bd9Sstevel@tonic-gate return ("CKR_TEMPLATE_INCOMPLETE"); 1567c478bd9Sstevel@tonic-gate case CKR_TEMPLATE_INCONSISTENT: 1577c478bd9Sstevel@tonic-gate return ("CKR_TEMPLATE_INCONSISTENT"); 1587c478bd9Sstevel@tonic-gate case CKR_TOKEN_NOT_PRESENT: 1597c478bd9Sstevel@tonic-gate return ("CKR_TOKEN_NOT_PRESENT"); 1607c478bd9Sstevel@tonic-gate case CKR_TOKEN_NOT_RECOGNIZED: 1617c478bd9Sstevel@tonic-gate return ("CKR_TOKEN_NOT_RECOGNIZED"); 1627c478bd9Sstevel@tonic-gate case CKR_TOKEN_WRITE_PROTECTED: 1637c478bd9Sstevel@tonic-gate return ("CKR_TOKEN_WRITE_PROTECTED"); 1647c478bd9Sstevel@tonic-gate case CKR_UNWRAPPING_KEY_HANDLE_INVALID: 1657c478bd9Sstevel@tonic-gate return ("CKR_UNWRAPPING_KEY_HANDLE_INVALID"); 1667c478bd9Sstevel@tonic-gate case CKR_UNWRAPPING_KEY_SIZE_RANGE: 1677c478bd9Sstevel@tonic-gate return ("CKR_UNWRAPPING_KEY_SIZE_RANGE"); 1687c478bd9Sstevel@tonic-gate case CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT: 1697c478bd9Sstevel@tonic-gate return ("CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT"); 1707c478bd9Sstevel@tonic-gate case CKR_USER_ALREADY_LOGGED_IN: 1717c478bd9Sstevel@tonic-gate return ("CKR_USER_ALREADY_LOGGED_IN"); 1727c478bd9Sstevel@tonic-gate case CKR_USER_NOT_LOGGED_IN: 1737c478bd9Sstevel@tonic-gate return ("CKR_USER_NOT_LOGGED_IN"); 1747c478bd9Sstevel@tonic-gate case CKR_USER_PIN_NOT_INITIALIZED: 1757c478bd9Sstevel@tonic-gate return ("CKR_USER_PIN_NOT_INITIALIZED"); 1767c478bd9Sstevel@tonic-gate case CKR_USER_TYPE_INVALID: 1777c478bd9Sstevel@tonic-gate return ("CKR_USER_TYPE_INVALID"); 1787c478bd9Sstevel@tonic-gate case CKR_USER_ANOTHER_ALREADY_LOGGED_IN: 1797c478bd9Sstevel@tonic-gate return ("CKR_USER_ANOTHER_ALREADY_LOGGED_IN"); 1807c478bd9Sstevel@tonic-gate case CKR_USER_TOO_MANY_TYPES: 1817c478bd9Sstevel@tonic-gate return ("CKR_USER_TOO_MANY_TYPES"); 1827c478bd9Sstevel@tonic-gate case CKR_WRAPPED_KEY_INVALID: 1837c478bd9Sstevel@tonic-gate return ("CKR_WRAPPED_KEY_INVALID"); 1847c478bd9Sstevel@tonic-gate case CKR_WRAPPED_KEY_LEN_RANGE: 1857c478bd9Sstevel@tonic-gate return ("CKR_WRAPPED_KEY_LEN_RANGE"); 1867c478bd9Sstevel@tonic-gate case CKR_WRAPPING_KEY_HANDLE_INVALID: 1877c478bd9Sstevel@tonic-gate return ("CKR_WRAPPING_KEY_HANDLE_INVALID"); 1887c478bd9Sstevel@tonic-gate case CKR_WRAPPING_KEY_SIZE_RANGE: 1897c478bd9Sstevel@tonic-gate return ("CKR_WRAPPING_KEY_SIZE_RANGE"); 1907c478bd9Sstevel@tonic-gate case CKR_WRAPPING_KEY_TYPE_INCONSISTENT: 1917c478bd9Sstevel@tonic-gate return ("CKR_WRAPPING_KEY_TYPE_INCONSISTENT"); 1927c478bd9Sstevel@tonic-gate case CKR_RANDOM_SEED_NOT_SUPPORTED: 1937c478bd9Sstevel@tonic-gate return ("CKR_RANDOM_SEED_NOT_SUPPORTED"); 1947c478bd9Sstevel@tonic-gate case CKR_RANDOM_NO_RNG: 1957c478bd9Sstevel@tonic-gate return ("CKR_RANDOM_NO_RNG"); 1967c478bd9Sstevel@tonic-gate case CKR_DOMAIN_PARAMS_INVALID: 1977c478bd9Sstevel@tonic-gate return ("CKR_DOMAIN_PARAMS_INVALID"); 1987c478bd9Sstevel@tonic-gate case CKR_BUFFER_TOO_SMALL: 1997c478bd9Sstevel@tonic-gate return ("CKR_BUFFER_TOO_SMALL"); 2007c478bd9Sstevel@tonic-gate case CKR_SAVED_STATE_INVALID: 2017c478bd9Sstevel@tonic-gate return ("CKR_SAVED_STATE_INVALID"); 2027c478bd9Sstevel@tonic-gate case CKR_INFORMATION_SENSITIVE: 2037c478bd9Sstevel@tonic-gate return ("CKR_INFORMATION_SENSITIVE"); 2047c478bd9Sstevel@tonic-gate case CKR_STATE_UNSAVEABLE: 2057c478bd9Sstevel@tonic-gate return ("CKR_STATE_UNSAVEABLE"); 2067c478bd9Sstevel@tonic-gate case CKR_CRYPTOKI_NOT_INITIALIZED: 2077c478bd9Sstevel@tonic-gate return ("CKR_CRYPTOKI_NOT_INITIALIZED"); 2087c478bd9Sstevel@tonic-gate case CKR_CRYPTOKI_ALREADY_INITIALIZED: 2097c478bd9Sstevel@tonic-gate return ("CKR_CRYPTOKI_ALREADY_INITIALIZED"); 2107c478bd9Sstevel@tonic-gate case CKR_MUTEX_BAD: 2117c478bd9Sstevel@tonic-gate return ("CKR_MUTEX_BAD"); 2127c478bd9Sstevel@tonic-gate case CKR_MUTEX_NOT_LOCKED: 2137c478bd9Sstevel@tonic-gate return ("CKR_MUTEX_NOT_LOCKED"); 2147c478bd9Sstevel@tonic-gate case CKR_VENDOR_DEFINED: 2157c478bd9Sstevel@tonic-gate return ("CKR_VENDOR_DEFINED"); 2167c478bd9Sstevel@tonic-gate default: 2177c478bd9Sstevel@tonic-gate /* rv not found */ 2187c478bd9Sstevel@tonic-gate (void) snprintf(errstr, sizeof (errstr), 2197c478bd9Sstevel@tonic-gate "Unknown return code: 0x%lx", rv); 2207c478bd9Sstevel@tonic-gate return (errstr); 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate } 223