metaObjectManager.c revision 7b79d84636ec82b45f00c982cf6810db81852d17
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * CDDL HEADER START
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * The contents of this file are subject to the terms of the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Common Development and Distribution License (the "License").
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * You may not use this file except in compliance with the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * See the License for the specific language governing permissions
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * and limitations under the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * When distributing Covered Code, include this CDDL HEADER in each
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * If applicable, add the following below this CDDL HEADER, with the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * fields enclosed by brackets "[]" replaced with your own identifying
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * information: Portions Copyright [yyyy] [name of copyright owner]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * CDDL HEADER END
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Use is subject to license terms.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* Size of the template for creating key used for wrap/unwrap */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Information necessary to create keys for C_WrapKey/C_UnwrapKey
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct _wrap_info {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CK_OBJECT_CLASS class; /* class of the key for wrap/unwrap */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CK_KEY_TYPE key_type; /* key type of key for wrap/unwrap */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CK_MECHANISM_TYPE mech_type; /* mech used for wrap/unwrap */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {CKO_SECRET_KEY, CKK_AES, 16, CKM_AES_CBC_PAD, 16, B_FALSE, B_FALSE},
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {CKO_SECRET_KEY, CKK_DES3, 24, CKM_DES3_CBC_PAD, 8, B_FALSE, B_FALSE},
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {CKO_SECRET_KEY, CKK_DES, 8, CKM_DES_CBC_PAD, 8, B_FALSE, B_FALSE},
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic unsigned int num_common_wrap_info =
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {CKO_SECRET_KEY, CKK_SKIPJACK, 12, CKM_SKIPJACK_WRAP, 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic unsigned int num_special_wrap_info =
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic unsigned int num_rsa_wrap_info =
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Public and private exponent, and Module value for
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * creating the RSA public/private key.
static CK_RV
return (CKR_FUNCTION_FAILED);
return (CKR_FUNCTION_FAILED);
return (CKR_OK);
return (CKR_OBJECT_HANDLE_INVALID);
return (CKR_OBJECT_HANDLE_INVALID);
return (CKR_OK);
return (CKR_HOST_MEMORY);
return (CKR_HOST_MEMORY);
return (CKR_HOST_MEMORY);
return (CKR_OK);
count++;
count++;
return (rv);
count = 0;
switch (class) {
case CKO_PRIVATE_KEY:
case CKO_SECRET_KEY:
case CKO_PUBLIC_KEY:
count++;
if (count > 0) {
return (rv);
if (is_token)
return (CKR_OK);
if (!have_object_lock) {
return (CKR_OBJECT_HANDLE_INVALID);
if (!have_list_lock) {
if (!have_list_lock) {
return (CKR_OK);
CK_ULONG i;
return (save_rv);
return (CKR_HOST_MEMORY);
return (CKR_OK);
if (isToken) {
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
num_attrs_with_val = 0;
for (i = 0; i < num_attrs; i++) {
goto finish;
goto finish;
goto finish;
for (i = 0; i < num_attrs_with_val; i++) {
goto finish;
if (session)
if (attrs) {
for (i = 0; i < num_attrs; i++) {
if (attrs_with_val) {
for (i = 0; i < num_attrs; i++) {
return (rv);
* The same template will be used for all wrapping/unwrapping keys all
static CK_RV
return (rv);
static CK_RV
return (rv);
return (rv);
return (rv);
return (CKR_OK);
static CK_RV
int *first_src_mech)
for (i = 0; i < num_info; i++) {
return (rv);
return (rv);
*first_both_mech = i;
return (CKR_OK);
*first_src_mech = i;
return (CKR_OK);
* Determine the wrapping/unwrapping mechanism to be used
static CK_RV
unsigned int num_wrap_info;
for (i = 0; i < num_special_wrap_info; i++) {
!= CKM_SKIPJACK_WRAP) {
goto finish;
goto finish;
if (src_supports) {
&(special_wrap_info[i]),
sizeof (wrap_info_t));
goto finish;
goto finish;
goto finish;
sizeof (wrap_info_t));
goto finish;
goto finish;
sizeof (wrap_info_t));
goto finish;
sizeof (wrap_info_t));
sizeof (wrap_info_t));
return (rv);
static CK_RV
return (rv);
goto finish;
goto finish;
goto finish;
if (pkcs11_get_urandom(
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
goto unwrap_in_source;
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
= tmp_slot_obj;
B_FALSE);
goto finish;
if (unwrappingKey) {
if (wrappingKey) {
if (tmp_slot_obj) {
if (tmp_meta_obj) {
B_TRUE);
if (tmp_meta_session) {
if (wrappedKey) {
if (src_slot_session) {
return (rv);
return (CKR_OK);
return (CKR_FUNCTION_FAILED);
return (CKR_FUNCTION_FAILED);
goto finish;
return (CKR_FUNCTION_FAILED);
goto finish;
goto finish;
if (newclone)
return (rv);
static CK_RV
size_t i, c = 0;
goto finish;
for (i = 0; i < num_attributes; i++) {
goto finish;
return (rv);
if (!token_only) {
(void) pthread_rwlock_rdlock(
(void) pthread_rwlock_rdlock(
(void) pthread_rwlock_unlock(
(void) pthread_rwlock_unlock(
return (object);
return (object);
goto finish;
goto finish;
return (save_rv);
if (!metaslot_auto_key_migrate ||
goto failure;
goto failure;
} else if (tmpl_len > 0) {
goto failure;
switch (keytype) {
case CKK_RSA:
case CKK_EC:
case CKK_DH:
goto failure;
goto failure;
goto failure;
goto failure;
return (B_TRUE);
return (B_FALSE);
return (B_FALSE);
if (!create) {
goto failure;
goto failure;
return (B_TRUE);
return (B_FALSE);
return (CKR_OK);
return (CKR_FUNCTION_FAILED);
return (CKR_OK);
return (CKR_FUNCTION_FAILED);
return (CKR_OK);
static CK_RV
goto cleanup;
goto cleanup;
return (rv);
return (rv);
if (rv > 0)
return (CKR_FUNCTION_FAILED);
if (rv > 0)
return (rv);
goto failure;
goto failure;
goto failure;
if (!failover)
goto failure;
goto failure;
return (CKR_OK);
return (rv);