本文整理汇总了C++中Tspi_Context_CreateObject函数的典型用法代码示例。如果您正苦于以下问题:C++ Tspi_Context_CreateObject函数的具体用法?C++ Tspi_Context_CreateObject怎么用?C++ Tspi_Context_CreateObject使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Tspi_Context_CreateObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: libhis_getkeyblob
libhis_getkeyblob()
{
//set default values
init_key_size = TSS_KEY_SIZE_DEFAULT;
init_key_type = TSS_KEY_TYPE_DEFAULT;
init_key_authorized = TSS_KEY_AUTHORIZATION;
init_key_migratable = TSS_KEY_NOT_MIGRATABLE;
init_key_volatile = TSS_KEY_VOLATILE;
binitialized = false;
//create a context object
result = Tspi_Context_Create(&hcontext);
if(result != TSS_SUCCESS) throw libhis_exception("Create Context", result);
//create an SRK object
result = Tspi_Context_CreateObject(hcontext, TSS_OBJECT_TYPE_RSAKEY, TSS_KEY_TSP_SRK, &hkey_srk);
if(result != TSS_SUCCESS) throw libhis_exception("Create SRK", result);
//Create SRK policy
result = Tspi_Context_CreateObject(hcontext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hpolicy_srk);
if(result != TSS_SUCCESS) throw libhis_exception("Create SRK Policy", result);
//Create key policy
result = Tspi_Context_CreateObject(hcontext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hpolicy_key);
if(result != TSS_SUCCESS) throw libhis_exception("Create key Policy", result);
}
示例2: libhis_changeownership
libhis_changeownership()
{
//create a context object
result = Tspi_Context_Create(&hcontext);
if(result != TSS_SUCCESS) throw libhis_exception("Create Conntext", result);
//Create TPM policy
result = Tspi_Context_CreateObject(hcontext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hpolicy_tpm);
if(result != TSS_SUCCESS) throw libhis_exception("Create TPM Policy", result);
//Create new policy
result = Tspi_Context_CreateObject(hcontext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hpolicy_new);
if(result != TSS_SUCCESS) throw libhis_exception("Create New Policy", result);
}
示例3: cmd_auth
/*ARGSUSED*/
int
cmd_auth(TSS_HCONTEXT hContext, TSS_HTPM hTPM, int argc, char *argv[])
{
TSS_RESULT ret;
TSS_HPOLICY hNewPolicy;
if (set_object_policy(hTPM, TSS_SECRET_MODE_POPUP,
gettext("= TPM owner passphrase ="), 0, NULL))
return (ERR_FAIL);
/* policy object for new passphrase */
ret = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY,
TSS_POLICY_USAGE, &hNewPolicy);
if (ret) {
print_error(ret, gettext("Create policy object"));
return (ERR_FAIL);
}
if (set_policy_options(hNewPolicy, TSS_SECRET_MODE_POPUP,
gettext("= New TPM owner passphrase ="), 0, NULL))
return (ERR_FAIL);
ret = Tspi_ChangeAuth(hTPM, NULL, hNewPolicy);
if (ret && ret != TSP_ERROR(TSS_E_POLICY_NO_SECRET)) {
print_error(ret, gettext("Change authorization"));
return (ERR_FAIL);
}
return (0);
}
示例4: cmd_init
/*ARGSUSED*/
int
cmd_init(TSS_HCONTEXT hContext, TSS_HTPM hTPM, int argc, char *argv[])
{
TSS_RESULT ret;
TSS_HOBJECT hKeySRK;
if (set_object_policy(hTPM, TSS_SECRET_MODE_POPUP,
gettext("= TPM owner passphrase ="), 0, NULL))
return (ERR_FAIL);
ret = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY,
TSS_KEY_TSP_SRK | TSS_KEY_AUTHORIZATION, &hKeySRK);
if (ret) {
print_error(ret, gettext("Create storage root key"));
return (ERR_FAIL);
}
if (set_object_policy(hKeySRK, TSS_SECRET_MODE_SHA1, NULL,
sizeof (well_known), well_known))
return (ERR_FAIL);
ret = Tspi_TPM_TakeOwnership(hTPM, hKeySRK, NULL);
if (ret == TPM_E_NO_ENDORSEMENT) {
if (createek(hContext, hTPM))
return (ERR_FAIL);
ret = Tspi_TPM_TakeOwnership(hTPM, hKeySRK, NULL);
}
if (ret) {
print_error(ret, gettext("Take ownership"));
return (ERR_FAIL);
}
return (0);
}
示例5: tpm_create_srk_policy
static int tpm_create_srk_policy(void *secret)
{
TSS_RESULT result;
UINT32 secret_len;
if (secret_mode == TSS_SECRET_MODE_SHA1)
secret_len = SHA_DIGEST_LENGTH;
else {
secret_len = (secret == NULL) ? 0 : strlen((char *)secret);
DBG("Using SRK secret = %s", (BYTE *)secret);
}
if (hSRKPolicy == NULL_HPOLICY) {
DBG("Creating SRK policy");
if ((result = Tspi_Context_CreateObject(hContext,
TSS_OBJECT_TYPE_POLICY,
TSS_POLICY_USAGE,
&hSRKPolicy))) {
TSSerr(TPM_F_TPM_CREATE_SRK_POLICY,
TPM_R_REQUEST_FAILED);
return 0;
}
}
if ((result = Tspi_Policy_SetSecret(hSRKPolicy, secret_mode,
secret_len, (BYTE *)secret))) {
TSSerr(TPM_F_TPM_CREATE_SRK_POLICY, TPM_R_REQUEST_FAILED);
return 0;
}
return 1;
}
示例6: initbind
void initbind(unsigned int in_size)
{
//set the type
init_key_type = TSS_KEY_TYPE_BIND;
//set the key size
if(in_size == 0)
init_key_size = TSS_KEY_SIZE_DEFAULT;
else if(in_size == 512)
init_key_size = TSS_KEY_SIZE_512;
else if(in_size == 1024)
init_key_size = TSS_KEY_SIZE_1024;
else if(in_size == 2048)
init_key_size = TSS_KEY_SIZE_2048;
else if(in_size == 4096)
init_key_size = TSS_KEY_SIZE_4096;
else if(in_size == 8192)
init_key_size = TSS_KEY_SIZE_8192;
else if(in_size == 16384)
init_key_size = TSS_KEY_SIZE_16384;
else throw libhis_exception("Invalid key size", 400);
//combine the init flags
init_key = init_key_size | init_key_type | init_key_authorized | init_key_migratable | init_key_volatile;
//Create key object
result = Tspi_Context_CreateObject(hcontext, TSS_OBJECT_TYPE_RSAKEY, init_key, &hkey_key);
if(result != TSS_SUCCESS) throw libhis_exception("Create key", result);
binitialized = true;
}
示例7: create_key
TPW_RESULT create_key(TSS_HCONTEXT tss_context, TSS_FLAG aflags, TSS_HKEY *user_key, TSS_HKEY p_key, char *auth, int authlen)
{
TSS_RESULT result;
TSS_HPOLICY policy;
if(!authlen)
aflags |= TSS_KEY_NO_AUTHORIZATION;
else
aflags |= TSS_KEY_AUTHORIZATION;
result = Tspi_Context_CreateObject(tss_context, TSS_OBJECT_TYPE_RSAKEY, aflags, user_key);
if(TSS_SUCCESS != result)
{
Log_Text("create_key", TPW_KEY_ERROR);
return TPW_KEY_ERROR;
}
if(authlen)
{
result = Tspi_Context_CreateObject(tss_context, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &policy);
result = policySetSecret(policy, authlen, auth);
if(TSS_SUCCESS != result)
{
Log_Text("setPolicy_in_create_key", TPW_POLICY_ERROR);
return TPW_POLICY_ERROR;
}
result = policyAssign(policy, *user_key);
if(TSS_SUCCESS != result)
{
Log_Text("assignPolicy_in_create_key", TPW_POLICY_ERROR);
return TPW_KEY_ERROR;
}
}
result = keyCreateKey(*user_key, p_key, 0);
if(TSS_SUCCESS != result)
{
Log_Text("Create_in_create_key", TPW_KEY_ERROR);
return TPW_KEY_ERROR;
}
return TPW_SUCCESS;
}
示例8: store_keys
/* create and store keys with the uuids in the @uuids parameter. Unregister
* any keys in the PS that are already stored. hParentKey should already be
* loaded and will become the parent of the key stored with uuids[0] */
TSS_RESULT
store_keys(TSS_HCONTEXT hContext, TSS_HKEY hParentKey, TSS_UUID *uuidParent0,
TSS_UUID **uuids)
{
int i;
TSS_RESULT result;
TSS_UUID *uuidParent;
TSS_HKEY hKey;
TSS_FLAG initFlags;
for (i = 0; uuids[i]; i++) {
/* unregister any keys in the PS that are in the way */
if ((result = Tspi_Context_UnregisterKey(hContext,
TSS_PS_TYPE_SYSTEM,
*uuids[i], &hKey)) &&
(TSS_ERROR_CODE(result) != TSS_E_PS_KEY_NOTFOUND)) {
print_error("Tspi_Context_UnregisterKey", result);
return result;
}
}
initFlags = TSS_KEY_SIZE_2048 | TSS_KEY_TYPE_STORAGE |
TSS_KEY_NO_AUTHORIZATION;
uuidParent = uuidParent0;
for (i = 0; uuids[i]; i++) {
/* create the keys and register them */
if ((result = Tspi_Context_CreateObject(hContext,
TSS_OBJECT_TYPE_RSAKEY,
initFlags, &hKey))) {
print_error("Tspi_Context_CreateObject", result);
return result;
}
if ((result = Tspi_Key_CreateKey(hKey, hParentKey, 0))) {
print_error("Tspi_Key_CreateKey", result);
return result;
}
/* load key so that the child can be created */
if ((result = Tspi_Key_LoadKey(hKey, hParentKey))) {
print_error("Tspi_Key_LoadKey", result);
return result;
}
/* register the new key */
if ((result = Tspi_Context_RegisterKey(hContext, hKey,
TSS_PS_TYPE_SYSTEM,
*uuids[i],
TSS_PS_TYPE_SYSTEM,
*uuidParent))) {
print_error("Tspi_Context_RegisterKey", result);
return result;
}
hParentKey = hKey;
uuidParent = uuids[i];
}
return TSS_SUCCESS;
}
示例9: main_v1_1
int
main_v1_1(void){
char *nameOfFunction = "Tspi_Context_CreateObject02";
TSS_HCONTEXT hContext;
TSS_HKEY hSignatureKey;
TSS_RESULT result;
print_begin_test(nameOfFunction);
//Create Context
result = Tspi_Context_Create(&hContext);
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Create ", result);
exit(result);
}
//Connect Context
result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Connect ", result);
Tspi_Context_Close(hContext);
exit(result);
}
//Create Object
result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH,
TSS_KEY_SIZE_2048 | TSS_KEY_TYPE_SIGNING |
TSS_KEY_MIGRATABLE, &hSignatureKey);
if (TSS_ERROR_CODE(result) != TSS_E_INVALID_OBJECT_INITFLAG){
if(!checkNonAPI(result)){
print_error(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_CloseObject(hContext, hSignatureKey);
Tspi_Context_Close(hContext);
exit(result);
}
else{
print_error_nonapi(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_CloseObject(hContext, hSignatureKey);
Tspi_Context_Close(hContext);
exit(result);
}
}
else{
print_success(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_CloseObject(hContext, hSignatureKey);
Tspi_Context_Close(hContext);
exit(0);
}
}
示例10: main_v1_1
int main_v1_1(void)
{
char *function = "Tspi_Hash_GetHashValue04";
TSS_HCONTEXT hContext;
TSS_HHASH hHash;
UINT32 ulHashValueLength, exitCode = 0;
BYTE *rgbHashValue, hashBuf[20];
TSS_RESULT result;
print_begin_test(function);
// Create Context
result = Tspi_Context_Create(&hContext);
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Create", result);
exit(result);
}
// Connect to Context
result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Connect", result);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(result);
}
result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH,
TSS_HASH_SHA1, &hHash);
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_CreateObject (hash)", result);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(result);
}
result = Tspi_Hash_GetHashValue(hHash, &ulHashValueLength,
&rgbHashValue);
if (TSS_ERROR_CODE(result) != TSS_E_HASH_NO_DATA) {
if (!(checkNonAPI(result))) {
print_error(function, result);
} else {
print_error_nonapi(function, result);
}
exitCode = result;
} else {
print_success(function, result);
}
print_end_test(function);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(exitCode);
}
示例11: tc_create_object
void
tc_create_object(TSS_HCONTEXT hContext, UINT32 type, UINT32 flags, TSS_HOBJECT *hObject)
{
TSS_RESULT result;
//Create Object
result = Tspi_Context_CreateObject(hContext, type, flags, hObject);
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_CreateObject", result);
print_error_exit(nameOfFunction, err_string(result));
Tspi_Context_Close(hContext);
exit(result);
}
}
示例12: initidentity
void initidentity()
{
//set the type
init_key_type = TSS_KEY_TYPE_IDENTITY;
//set the key size
init_key_size = TSS_KEY_SIZE_DEFAULT;
//combine the init flags
init_key = init_key_size | init_key_type | init_key_authorized | init_key_migratable | init_key_volatile;
//Create key object
result = Tspi_Context_CreateObject(hcontext, TSS_OBJECT_TYPE_RSAKEY, init_key, &hkey_key);
if(result != TSS_SUCCESS) throw libhis_exception("Create key", result);
binitialized = true;
}
示例13: tpm_sign_fn
static int
tpm_sign_fn(gnutls_privkey_t key, void *_s,
const gnutls_datum_t * data, gnutls_datum_t * sig)
{
struct tpm_ctx_st *s = _s;
TSS_HHASH hash;
int err;
_gnutls_debug_log("TPM sign function called for %u bytes.\n",
data->size);
err =
Tspi_Context_CreateObject(s->tpm_ctx,
TSS_OBJECT_TYPE_HASH, TSS_HASH_OTHER,
&hash);
if (err) {
gnutls_assert();
_gnutls_debug_log("Failed to create TPM hash object: %s\n",
Trspi_Error_String(err));
return GNUTLS_E_PK_SIGN_FAILED;
}
err = Tspi_Hash_SetHashValue(hash, data->size, data->data);
if (err) {
gnutls_assert();
_gnutls_debug_log
("Failed to set value in TPM hash object: %s\n",
Trspi_Error_String(err));
Tspi_Context_CloseObject(s->tpm_ctx, hash);
return GNUTLS_E_PK_SIGN_FAILED;
}
err = Tspi_Hash_Sign(hash, s->tpm_key, &sig->size, &sig->data);
Tspi_Context_CloseObject(s->tpm_ctx, hash);
if (err) {
if (s->tpm_key_policy || err != TPM_E_AUTHFAIL)
_gnutls_debug_log
("TPM hash signature failed: %s\n",
Trspi_Error_String(err));
if (err == TPM_E_AUTHFAIL)
return GNUTLS_E_TPM_KEY_PASSWORD_ERROR;
else
return GNUTLS_E_PK_SIGN_FAILED;
}
return 0;
}
示例14: tpm_sign_fn
static int tpm_sign_fn(gnutls_privkey_t key, void *_vpninfo,
const gnutls_datum_t *data, gnutls_datum_t *sig)
{
struct openconnect_info *vpninfo = _vpninfo;
TSS_HHASH hash;
int err;
vpn_progress(vpninfo, PRG_TRACE,
_("TPM sign function called for %d bytes.\n"),
data->size);
err = Tspi_Context_CreateObject(vpninfo->tpm_context, TSS_OBJECT_TYPE_HASH,
TSS_HASH_OTHER, &hash);
if (err) {
vpn_progress(vpninfo, PRG_ERR,
_("Failed to create TPM hash object: %s\n"),
Trspi_Error_String(err));
return GNUTLS_E_PK_SIGN_FAILED;
}
err = Tspi_Hash_SetHashValue(hash, data->size, data->data);
if (err) {
vpn_progress(vpninfo, PRG_ERR,
_("Failed to set value in TPM hash object: %s\n"),
Trspi_Error_String(err));
Tspi_Context_CloseObject(vpninfo->tpm_context, hash);
return GNUTLS_E_PK_SIGN_FAILED;
}
err = Tspi_Hash_Sign(hash, vpninfo->tpm_key, &sig->size, &sig->data);
Tspi_Context_CloseObject(vpninfo->tpm_context, hash);
if (err) {
if (vpninfo->tpm_key_policy || err != TPM_E_AUTHFAIL)
vpn_progress(vpninfo, PRG_ERR,
_("TPM hash signature failed: %s\n"),
Trspi_Error_String(err));
if (err == TPM_E_AUTHFAIL)
return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
else
return GNUTLS_E_PK_SIGN_FAILED;
}
return 0;
}
示例15: createek
static int
createek(TSS_HCONTEXT hContext, TSS_HTPM hTPM)
{
TSS_RESULT ret;
TSS_HOBJECT hKeyEK;
TSS_VALIDATION ValidationData;
TPM_NONCE nonce;
TPM_DIGEST digest;
/* Create the empty key struct for EK */
ret = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY,
(TSS_KEY_NO_AUTHORIZATION | TSS_KEY_NON_VOLATILE |
TSS_KEY_NOT_MIGRATABLE | TSS_KEY_TYPE_STORAGE |
TSS_KEY_SIZE_2048 | TSS_KEY_NOT_CERTIFIED_MIGRATABLE |
TSS_KEY_STRUCT_KEY12 | TSS_KEY_EMPTY_KEY),
&hKeyEK);
if (ret) {
print_error(ret, gettext("Create endorsement key object"));
return (ERR_FAIL);
}
ValidationData.ulExternalDataLength = sizeof (nonce);
ValidationData.rgbExternalData = (BYTE *) &nonce;
ret = get_random(sizeof (nonce), (BYTE *) &nonce);
if (ret)
return (ERR_FAIL);
ValidationData.ulValidationDataLength = sizeof (digest);
ValidationData.rgbValidationData = (BYTE *) &digest;
ret = Tspi_TPM_CreateEndorsementKey(hTPM, hKeyEK, &ValidationData);
if (ret) {
print_error(ret, gettext("Create endorsement key"));
return (ERR_FAIL);
}
return (0);
}