0N/A/*
3261N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A */
0N/A
0N/A/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
0N/A *
0N/A * Redistribution and use in source and binary forms, with or without
0N/A * modification, are permitted provided that the following conditions are met:
0N/A *
0N/A * 1. Redistributions of source code must retain the above copyright notice,
0N/A * this list of conditions and the following disclaimer.
0N/A *
0N/A * 2. Redistributions in binary form must reproduce the above copyright notice,
0N/A * this list of conditions and the following disclaimer in the documentation
0N/A * and/or other materials provided with the distribution.
0N/A *
0N/A * 3. The end-user documentation included with the redistribution, if any, must
0N/A * include the following acknowledgment:
0N/A *
0N/A * "This product includes software developed by IAIK of Graz University of
0N/A * Technology."
0N/A *
0N/A * Alternately, this acknowledgment may appear in the software itself, if
0N/A * and wherever such third-party acknowledgments normally appear.
0N/A *
0N/A * 4. The names "Graz University of Technology" and "IAIK of Graz University of
0N/A * Technology" must not be used to endorse or promote products derived from
0N/A * this software without prior written permission.
0N/A *
0N/A * 5. Products derived from this software may not be called
0N/A * "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior
0N/A * written permission of Graz University of Technology.
0N/A *
0N/A * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
0N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
0N/A * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE
0N/A * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
0N/A * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
0N/A * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
0N/A * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0N/A * POSSIBILITY OF SUCH DAMAGE.
0N/A */
0N/A
0N/Apackage sun.security.pkcs11.wrapper;
0N/A
0N/Aimport java.util.*;
0N/A
0N/A
0N/A/**
0N/A * This is the superclass of all checked exceptions used by this package. An
0N/A * exception of this class indicates that a function call to the underlying
0N/A * PKCS#11 module returned a value not equal to CKR_OK. The application can get
0N/A * the returned value by calling getErrorCode(). A return value not equal to
0N/A * CKR_OK is the only reason for such an exception to be thrown.
0N/A * PKCS#11 defines the meaning of an error-code, which may depend on the
0N/A * context in which the error occurs.
0N/A *
0N/A * @author <a href="mailto:Karl.Scheibelhofer@iaik.at"> Karl Scheibelhofer </a>
0N/A * @invariants
0N/A */
0N/Apublic class PKCS11Exception extends Exception {
0N/A
0N/A /**
0N/A * The code of the error which was the reason for this exception.
0N/A */
0N/A protected long errorCode_;
0N/A
0N/A private static final Map<Long,String> errorMap;
0N/A
0N/A static {
0N/A int[] errorCodes = new int[] {
0N/A 0x00000000,
0N/A 0x00000001,
0N/A 0x00000002,
0N/A 0x00000003,
0N/A 0x00000005,
0N/A 0x00000006,
0N/A 0x00000007,
0N/A 0x00000008,
0N/A 0x00000009,
0N/A 0x0000000A,
0N/A 0x00000010,
0N/A 0x00000011,
0N/A 0x00000012,
0N/A 0x00000013,
0N/A 0x00000020,
0N/A 0x00000021,
0N/A 0x00000030,
0N/A 0x00000031,
0N/A 0x00000032,
0N/A 0x00000040,
0N/A 0x00000041,
0N/A 0x00000050,
0N/A 0x00000051,
0N/A 0x00000054,
0N/A 0x00000060,
0N/A 0x00000062,
0N/A 0x00000063,
0N/A 0x00000064,
0N/A 0x00000065,
0N/A 0x00000066,
0N/A 0x00000067,
0N/A 0x00000068,
0N/A 0x00000069,
0N/A 0x0000006A,
0N/A 0x00000070,
0N/A 0x00000071,
0N/A 0x00000082,
0N/A 0x00000090,
0N/A 0x00000091,
0N/A 0x000000A0,
0N/A 0x000000A1,
0N/A 0x000000A2,
0N/A 0x000000A3,
0N/A 0x000000A4,
0N/A 0x000000B0,
0N/A 0x000000B1,
0N/A 0x000000B3,
0N/A 0x000000B4,
0N/A 0x000000B5,
0N/A 0x000000B6,
0N/A 0x000000B7,
0N/A 0x000000B8,
0N/A 0x000000C0,
0N/A 0x000000C1,
0N/A 0x000000D0,
0N/A 0x000000D1,
0N/A 0x000000E0,
0N/A 0x000000E1,
0N/A 0x000000E2,
0N/A 0x000000F0,
0N/A 0x000000F1,
0N/A 0x000000F2,
0N/A 0x00000100,
0N/A 0x00000101,
0N/A 0x00000102,
0N/A 0x00000103,
0N/A 0x00000104,
0N/A 0x00000105,
0N/A 0x00000110,
0N/A 0x00000112,
0N/A 0x00000113,
0N/A 0x00000114,
0N/A 0x00000115,
0N/A 0x00000120,
0N/A 0x00000121,
2308N/A 0x00000130,
0N/A 0x00000150,
0N/A 0x00000160,
0N/A 0x00000170,
0N/A 0x00000180,
0N/A 0x00000190,
0N/A 0x00000191,
0N/A 0x000001A0,
0N/A 0x000001A1,
2308N/A 0x00000200,
0N/A 0x80000000,
0N/A };
0N/A String[] errorMessages = new String[] {
0N/A "CKR_OK",
0N/A "CKR_CANCEL",
0N/A "CKR_HOST_MEMORY",
0N/A "CKR_SLOT_ID_INVALID",
0N/A "CKR_GENERAL_ERROR",
0N/A "CKR_FUNCTION_FAILED",
0N/A "CKR_ARGUMENTS_BAD",
0N/A "CKR_NO_EVENT",
0N/A "CKR_NEED_TO_CREATE_THREADS",
0N/A "CKR_CANT_LOCK",
0N/A "CKR_ATTRIBUTE_READ_ONLY",
0N/A "CKR_ATTRIBUTE_SENSITIVE",
0N/A "CKR_ATTRIBUTE_TYPE_INVALID",
0N/A "CKR_ATTRIBUTE_VALUE_INVALID",
0N/A "CKR_DATA_INVALID",
0N/A "CKR_DATA_LEN_RANGE",
0N/A "CKR_DEVICE_ERROR",
0N/A "CKR_DEVICE_MEMORY",
0N/A "CKR_DEVICE_REMOVED",
0N/A "CKR_ENCRYPTED_DATA_INVALID",
0N/A "CKR_ENCRYPTED_DATA_LEN_RANGE",
0N/A "CKR_FUNCTION_CANCELED",
0N/A "CKR_FUNCTION_NOT_PARALLEL",
0N/A "CKR_FUNCTION_NOT_SUPPORTED",
0N/A "CKR_KEY_HANDLE_INVALID",
0N/A "CKR_KEY_SIZE_RANGE",
0N/A "CKR_KEY_TYPE_INCONSISTENT",
0N/A "CKR_KEY_NOT_NEEDED",
0N/A "CKR_KEY_CHANGED",
0N/A "CKR_KEY_NEEDED",
0N/A "CKR_KEY_INDIGESTIBLE",
0N/A "CKR_KEY_FUNCTION_NOT_PERMITTED",
0N/A "CKR_KEY_NOT_WRAPPABLE",
0N/A "CKR_KEY_UNEXTRACTABLE",
0N/A "CKR_MECHANISM_INVALID",
0N/A "CKR_MECHANISM_PARAM_INVALID",
0N/A "CKR_OBJECT_HANDLE_INVALID",
0N/A "CKR_OPERATION_ACTIVE",
0N/A "CKR_OPERATION_NOT_INITIALIZED",
0N/A "CKR_PIN_INCORRECT",
0N/A "CKR_PIN_INVALID",
0N/A "CKR_PIN_LEN_RANGE",
0N/A "CKR_PIN_EXPIRED",
0N/A "CKR_PIN_LOCKED",
0N/A "CKR_SESSION_CLOSED",
0N/A "CKR_SESSION_COUNT",
0N/A "CKR_SESSION_HANDLE_INVALID",
0N/A "CKR_SESSION_PARALLEL_NOT_SUPPORTED",
0N/A "CKR_SESSION_READ_ONLY",
0N/A "CKR_SESSION_EXISTS",
0N/A "CKR_SESSION_READ_ONLY_EXISTS",
0N/A "CKR_SESSION_READ_WRITE_SO_EXISTS",
0N/A "CKR_SIGNATURE_INVALID",
0N/A "CKR_SIGNATURE_LEN_RANGE",
0N/A "CKR_TEMPLATE_INCOMPLETE",
0N/A "CKR_TEMPLATE_INCONSISTENT",
0N/A "CKR_TOKEN_NOT_PRESENT",
0N/A "CKR_TOKEN_NOT_RECOGNIZED",
0N/A "CKR_TOKEN_WRITE_PROTECTED",
0N/A "CKR_UNWRAPPING_KEY_HANDLE_INVALID",
0N/A "CKR_UNWRAPPING_KEY_SIZE_RANGE",
0N/A "CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT",
0N/A "CKR_USER_ALREADY_LOGGED_IN",
0N/A "CKR_USER_NOT_LOGGED_IN",
0N/A "CKR_USER_PIN_NOT_INITIALIZED",
0N/A "CKR_USER_TYPE_INVALID",
0N/A "CKR_USER_ANOTHER_ALREADY_LOGGED_IN",
0N/A "CKR_USER_TOO_MANY_TYPES",
0N/A "CKR_WRAPPED_KEY_INVALID",
0N/A "CKR_WRAPPED_KEY_LEN_RANGE",
0N/A "CKR_WRAPPING_KEY_HANDLE_INVALID",
0N/A "CKR_WRAPPING_KEY_SIZE_RANGE",
0N/A "CKR_WRAPPING_KEY_TYPE_INCONSISTENT",
0N/A "CKR_RANDOM_SEED_NOT_SUPPORTED",
0N/A "CKR_RANDOM_NO_RNG",
2308N/A "CKR_DOMAIN_PARAMS_INVALID",
0N/A "CKR_BUFFER_TOO_SMALL",
0N/A "CKR_SAVED_STATE_INVALID",
0N/A "CKR_INFORMATION_SENSITIVE",
0N/A "CKR_STATE_UNSAVEABLE",
0N/A "CKR_CRYPTOKI_NOT_INITIALIZED",
0N/A "CKR_CRYPTOKI_ALREADY_INITIALIZED",
0N/A "CKR_MUTEX_BAD",
0N/A "CKR_MUTEX_NOT_LOCKED",
2308N/A "CKR_FUNCTION_REJECTED",
0N/A "CKR_VENDOR_DEFINED",
0N/A };
0N/A errorMap = new HashMap<Long,String>();
0N/A for (int i = 0; i < errorCodes.length; i++) {
0N/A errorMap.put(Long.valueOf(errorCodes[i]), errorMessages[i]);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Constructor taking the error code as defined for the CKR_* constants
0N/A * in PKCS#11.
0N/A */
0N/A public PKCS11Exception(long errorCode) {
0N/A errorCode_ = errorCode;
0N/A }
0N/A
0N/A /**
0N/A * This method gets the corresponding text error message from
0N/A * a property file. If this file is not available, it returns the error
0N/A * code as a hex-string.
0N/A *
0N/A * @return The message or the error code; e.g. "CKR_DEVICE_ERROR" or
0N/A * "0x00000030".
0N/A * @preconditions
0N/A * @postconditions (result <> null)
0N/A */
0N/A public String getMessage() {
0N/A String message = errorMap.get(Long.valueOf(errorCode_));
0N/A if (message == null) {
0N/A message = "0x" + Functions.toFullHexString((int)errorCode_);
0N/A }
0N/A return message;
0N/A }
0N/A
0N/A /**
0N/A * Returns the PKCS#11 error code.
0N/A *
0N/A * @return The error code; e.g. 0x00000030.
0N/A * @preconditions
0N/A * @postconditions
0N/A */
0N/A public long getErrorCode() {
0N/A return errorCode_ ;
0N/A }
0N/A
0N/A}