/* * return a key blob from PS given a uuid */ TSS_RESULT psfile_get_key_by_uuid(int fd, TSS_UUID *uuid, BYTE *ret_buffer, UINT16 *ret_buffer_size) { int rc; UINT32 file_offset = 0; struct key_disk_cache *tmp; MUTEX_LOCK(disk_cache_lock); tmp = key_disk_cache_head; while (tmp) { if (memcmp(uuid, &tmp->uuid, sizeof(TSS_UUID)) || !(tmp->flags & CACHE_FLAG_VALID)) { tmp = tmp->next; continue; } /* jump to the location of the key blob */ file_offset = TSSPS_BLOB_DATA_OFFSET(tmp); rc = lseek(fd, file_offset, SEEK_SET); if (rc == ((off_t) - 1)) { LogError("lseek: %s", strerror(errno)); MUTEX_UNLOCK(disk_cache_lock); return TCSERR(TSS_E_INTERNAL_ERROR); } /* we found the key; file ptr is pointing at the blob */ if (*ret_buffer_size < tmp->blob_size) { /* not enough room */ MUTEX_UNLOCK(disk_cache_lock); return TCSERR(TSS_E_FAIL); } if ((rc = read_data(fd, ret_buffer, tmp->blob_size))) { LogError("%s", __FUNCTION__); MUTEX_UNLOCK(disk_cache_lock); return rc; } *ret_buffer_size = tmp->blob_size; LogDebugUnrollKey(ret_buffer); MUTEX_UNLOCK(disk_cache_lock); return TSS_SUCCESS; } MUTEX_UNLOCK(disk_cache_lock); /* key not found */ return TCSERR(TSS_E_FAIL); }
TSS_RESULT TCS_RegisterKey_Internal(TCS_CONTEXT_HANDLE hContext, /* in */ TSS_UUID *WrappingKeyUUID, /* in */ TSS_UUID *KeyUUID, /* in */ UINT32 cKeySize, /* in */ BYTE * rgbKey, /* in */ UINT32 cVendorData, /* in */ BYTE * gbVendorData) /* in */ { TSS_RESULT result; TSS_BOOL is_reg; if ((result = ctx_verify_context(hContext))) return result; /* Check if key is already regisitered */ if (isUUIDRegistered(KeyUUID, &is_reg) != TSS_SUCCESS) { LogError("Failed checking if UUID is registered."); return TCSERR(TSS_E_INTERNAL_ERROR); } if (is_reg == TRUE || TSS_UUID_IS_OWNEREVICT(KeyUUID)) { LogDebug("UUID is already registered"); return TCSERR(TSS_E_KEY_ALREADY_REGISTERED); } LogDebugUnrollKey(rgbKey); /* Go ahead and store it in system persistant storage */ if ((result = ps_write_key(KeyUUID, WrappingKeyUUID, gbVendorData, cVendorData, rgbKey, cKeySize))) { LogError("Error writing key to file"); return result; } return TSS_SUCCESS; }