Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/pkcs11/wrapper/PKCS11Exception.java
38920 views
/*1* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.2*/34/* Copyright (c) 2002 Graz University of Technology. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions are met:8*9* 1. Redistributions of source code must retain the above copyright notice,10* this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright notice,13* this list of conditions and the following disclaimer in the documentation14* and/or other materials provided with the distribution.15*16* 3. The end-user documentation included with the redistribution, if any, must17* include the following acknowledgment:18*19* "This product includes software developed by IAIK of Graz University of20* Technology."21*22* Alternately, this acknowledgment may appear in the software itself, if23* and wherever such third-party acknowledgments normally appear.24*25* 4. The names "Graz University of Technology" and "IAIK of Graz University of26* Technology" must not be used to endorse or promote products derived from27* this software without prior written permission.28*29* 5. Products derived from this software may not be called30* "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior31* written permission of Graz University of Technology.32*33* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED34* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED35* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR36* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE37* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,38* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,39* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,40* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON41* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,42* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY43* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE44* POSSIBILITY OF SUCH DAMAGE.45*/4647package sun.security.pkcs11.wrapper;4849import java.util.*;505152/**53* This is the superclass of all checked exceptions used by this package. An54* exception of this class indicates that a function call to the underlying55* PKCS#11 module returned a value not equal to CKR_OK. The application can get56* the returned value by calling getErrorCode(). A return value not equal to57* CKR_OK is the only reason for such an exception to be thrown.58* PKCS#11 defines the meaning of an error-code, which may depend on the59* context in which the error occurs.60*61* @author <a href="mailto:[email protected]"> Karl Scheibelhofer </a>62* @invariants63*/64public class PKCS11Exception extends Exception {65private static final long serialVersionUID = 4877072363729195L;6667/**68* The code of the error which was the reason for this exception.69*/70protected long errorCode_;7172private static final Map<Long,String> errorMap;7374static {75int[] errorCodes = new int[] {760x00000000,770x00000001,780x00000002,790x00000003,800x00000005,810x00000006,820x00000007,830x00000008,840x00000009,850x0000000A,860x00000010,870x00000011,880x00000012,890x00000013,900x0000001B,910x00000020,920x00000021,930x00000030,940x00000031,950x00000032,960x00000040,970x00000041,980x00000050,990x00000051,1000x00000054,1010x00000060,1020x00000062,1030x00000063,1040x00000064,1050x00000065,1060x00000066,1070x00000067,1080x00000068,1090x00000069,1100x0000006A,1110x00000070,1120x00000071,1130x00000082,1140x00000090,1150x00000091,1160x000000A0,1170x000000A1,1180x000000A2,1190x000000A3,1200x000000A4,1210x000000B0,1220x000000B1,1230x000000B3,1240x000000B4,1250x000000B5,1260x000000B6,1270x000000B7,1280x000000B8,1290x000000C0,1300x000000C1,1310x000000D0,1320x000000D1,1330x000000E0,1340x000000E1,1350x000000E2,1360x000000F0,1370x000000F1,1380x000000F2,1390x00000100,1400x00000101,1410x00000102,1420x00000103,1430x00000104,1440x00000105,1450x00000110,1460x00000112,1470x00000113,1480x00000114,1490x00000115,1500x00000120,1510x00000121,1520x00000130,1530x00000150,1540x00000160,1550x00000170,1560x00000180,1570x00000190,1580x00000191,1590x000001A0,1600x000001A1,1610x000001B0,1620x000001B1,1630x000001B5,1640x000001B6,1650x000001B7,1660x000001B8,1670x000001B9,1680x00000200,1690x80000000,170};171String[] errorMessages = new String[] {172"CKR_OK",173"CKR_CANCEL",174"CKR_HOST_MEMORY",175"CKR_SLOT_ID_INVALID",176"CKR_GENERAL_ERROR",177"CKR_FUNCTION_FAILED",178"CKR_ARGUMENTS_BAD",179"CKR_NO_EVENT",180"CKR_NEED_TO_CREATE_THREADS",181"CKR_CANT_LOCK",182"CKR_ATTRIBUTE_READ_ONLY",183"CKR_ATTRIBUTE_SENSITIVE",184"CKR_ATTRIBUTE_TYPE_INVALID",185"CKR_ATTRIBUTE_VALUE_INVALID",186"CKR_ACTION_PROHIBITED",187"CKR_DATA_INVALID",188"CKR_DATA_LEN_RANGE",189"CKR_DEVICE_ERROR",190"CKR_DEVICE_MEMORY",191"CKR_DEVICE_REMOVED",192"CKR_ENCRYPTED_DATA_INVALID",193"CKR_ENCRYPTED_DATA_LEN_RANGE",194"CKR_FUNCTION_CANCELED",195"CKR_FUNCTION_NOT_PARALLEL",196"CKR_FUNCTION_NOT_SUPPORTED",197"CKR_KEY_HANDLE_INVALID",198"CKR_KEY_SIZE_RANGE",199"CKR_KEY_TYPE_INCONSISTENT",200"CKR_KEY_NOT_NEEDED",201"CKR_KEY_CHANGED",202"CKR_KEY_NEEDED",203"CKR_KEY_INDIGESTIBLE",204"CKR_KEY_FUNCTION_NOT_PERMITTED",205"CKR_KEY_NOT_WRAPPABLE",206"CKR_KEY_UNEXTRACTABLE",207"CKR_MECHANISM_INVALID",208"CKR_MECHANISM_PARAM_INVALID",209"CKR_OBJECT_HANDLE_INVALID",210"CKR_OPERATION_ACTIVE",211"CKR_OPERATION_NOT_INITIALIZED",212"CKR_PIN_INCORRECT",213"CKR_PIN_INVALID",214"CKR_PIN_LEN_RANGE",215"CKR_PIN_EXPIRED",216"CKR_PIN_LOCKED",217"CKR_SESSION_CLOSED",218"CKR_SESSION_COUNT",219"CKR_SESSION_HANDLE_INVALID",220"CKR_SESSION_PARALLEL_NOT_SUPPORTED",221"CKR_SESSION_READ_ONLY",222"CKR_SESSION_EXISTS",223"CKR_SESSION_READ_ONLY_EXISTS",224"CKR_SESSION_READ_WRITE_SO_EXISTS",225"CKR_SIGNATURE_INVALID",226"CKR_SIGNATURE_LEN_RANGE",227"CKR_TEMPLATE_INCOMPLETE",228"CKR_TEMPLATE_INCONSISTENT",229"CKR_TOKEN_NOT_PRESENT",230"CKR_TOKEN_NOT_RECOGNIZED",231"CKR_TOKEN_WRITE_PROTECTED",232"CKR_UNWRAPPING_KEY_HANDLE_INVALID",233"CKR_UNWRAPPING_KEY_SIZE_RANGE",234"CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT",235"CKR_USER_ALREADY_LOGGED_IN",236"CKR_USER_NOT_LOGGED_IN",237"CKR_USER_PIN_NOT_INITIALIZED",238"CKR_USER_TYPE_INVALID",239"CKR_USER_ANOTHER_ALREADY_LOGGED_IN",240"CKR_USER_TOO_MANY_TYPES",241"CKR_WRAPPED_KEY_INVALID",242"CKR_WRAPPED_KEY_LEN_RANGE",243"CKR_WRAPPING_KEY_HANDLE_INVALID",244"CKR_WRAPPING_KEY_SIZE_RANGE",245"CKR_WRAPPING_KEY_TYPE_INCONSISTENT",246"CKR_RANDOM_SEED_NOT_SUPPORTED",247"CKR_RANDOM_NO_RNG",248"CKR_DOMAIN_PARAMS_INVALID",249"CKR_BUFFER_TOO_SMALL",250"CKR_SAVED_STATE_INVALID",251"CKR_INFORMATION_SENSITIVE",252"CKR_STATE_UNSAVEABLE",253"CKR_CRYPTOKI_NOT_INITIALIZED",254"CKR_CRYPTOKI_ALREADY_INITIALIZED",255"CKR_MUTEX_BAD",256"CKR_MUTEX_NOT_LOCKED",257"CKR_NEW_PIN_MODE",258"CKR_NEXT_OTP",259"CKR_EXCEEDED_MAX_ITERATIONS",260"CKR_FIPS_SELF_TEST_FAILED",261"CKR_LIBRARY_LOAD_FAILED",262"CKR_PIN_TOO_WEAK",263"CKR_PUBLIC_KEY_INVALID",264"CKR_FUNCTION_REJECTED",265"CKR_VENDOR_DEFINED",266};267errorMap = new HashMap<Long,String>();268for (int i = 0; i < errorCodes.length; i++) {269errorMap.put(Long.valueOf(errorCodes[i]), errorMessages[i]);270}271}272273274/**275* Constructor taking the error code as defined for the CKR_* constants276* in PKCS#11.277*/278public PKCS11Exception(long errorCode) {279errorCode_ = errorCode;280}281282/**283* This method gets the corresponding text error message from284* a property file. If this file is not available, it returns the error285* code as a hex-string.286*287* @return The message or the error code; e.g. "CKR_DEVICE_ERROR" or288* "0x00000030".289* @preconditions290* @postconditions (result <> null)291*/292public String getMessage() {293String message = errorMap.get(Long.valueOf(errorCode_));294if (message == null) {295message = "0x" + Functions.toFullHexString((int)errorCode_);296}297return message;298}299300/**301* Returns the PKCS#11 error code.302*303* @return The error code; e.g. 0x00000030.304* @preconditions305* @postconditions306*/307public long getErrorCode() {308return errorCode_ ;309}310311}312313314