Cryptoki: a cryptographic Token Interface



Download 360.55 Kb.
Page96/196
Date22.12.2023
Size360.55 Kb.
#63026
1   ...   92   93   94   95   96   97   98   99   ...   196
v201-95
pkcs11-base-v2.40-cos01

C_CopyObject


CK_DEFINE_FUNCTION(CK_RV, C_CopyObject)(
CK_SESSION_HANDLE hSession,
CK_OBJECT_HANDLE hObject,
CK_ATTRIBUTE_PTR pTemplate,
CK_ULONG ulCount,
CK_OBJECT_HANDLE_PTR phNewObject
);
C_CopyObject copies an object, creating a new object for the copy. hSession is the session’s handle; hObject is the object’s handle; pTemplate points to the template for the new object; ulCount is the number of attributes in the template; phNewObject points to the location that receives the handle for the copy of the object.
The template may specify new values for any attributes of the object that can ordinarily be modified (e.g., in the course of copying a secret key, a key’s CKA_EXTRACTABLE attribute may be changed from TRUE to FALSE, but not the other way around. If this change is made, the new key’s CKA_NEVER_EXTRACTABLE attribute will have the value FALSE. Similarly, the template may specify that the new key’s CKA_SENSITIVE attribute be TRUE; the new key will have the same value for its CKA_ALWAYS_SENSITIVE attribute as the original key). It may also specify new values of the CKA_TOKEN and CKA_PRIVATE attributes (e.g., to copy a session object to a token object). If the template specifies a value of an attribute which is incompatible with other existing attributes of the object, the call fails with the return code CKR_TEMPLATE_INCONSISTENT.
If a call to C_CopyObject cannot support the precise template supplied to it, it will fail and return without creating any object.
Only session objects can be created during a read-only session. Only public objects can be created unless the normal user is logged in.
Return values: CKR_ATTRIBUTE_READ_ONLY, CKR_ATTRIBUTE_TYPE_INVALID, CKR_ATTRIBUTE_VALUE_INVALID, CKR_CRYPTOKI_NOT_INITIALIZED, CKR_DEVICE_ERROR, CKR_DEVICE_MEMORY, CKR_DEVICE_REMOVED, CKR_FUNCTION_FAILED, CKR_GENERAL_ERROR, CKR_HOST_MEMORY, CKR_OBJECT_HANDLE_INVALID, CKR_OK, CKR_SESSION_CLOSED, CKR_SESSION_HANDLE_INVALID, CKR_SESSION_READ_ONLY, CKR_TEMPLATE_INCONSISTENT, CKR_TOKEN_WRITE_PROTECTED, CKR_USER_NOT_LOGGED_IN.
Example:
CK_SESSION_HANDLE hSession;
CK_OBJECT_HANDLE hKey, hNewKey;
CK_OBJECT_CLASS keyClass = CKO_SECRET_KEY;
CK_KEY_TYPE keyType = CKK_DES;
CK_BYTE id[] = {...};
CK_BYTE keyValue[] = {...};
CK_BYTE false = FALSE;
CK_BYTE true = TRUE;
CK_ATTRIBUTE keyTemplate[] = {
{CKA_CLASS, &keyClass, sizeof(keyClass)},
{CKA_KEY_TYPE, &keyType, sizeof(keyType)},
{CKA_TOKEN, &false, sizeof(false)},
{CKA_ID, id, sizeof(id)},
{CKA_VALUE, keyValue, sizeof(keyValue)}
};
CK_ATTRIBUTE copyTemplate[] = {
{CKA_TOKEN, &true, sizeof(true)}
};
CK_RV rv;

.
.
.


/* Create a DES secret key session object */
rv = C_CreateObject(hSession, &keyTemplate, 5, &hKey);
if (rv == CKR_OK) {
/* Create a copy which is a token object */
rv = C_CopyObject(hSession, hKey, ©Template, 1, &hNewKey);
.
.
.
}
1   ...   92   93   94   95   96   97   98   99   ...   196




The database is protected by copyright ©ininet.org 2024
send message

    Main page