diff options
Diffstat (limited to 'src/tspi/rpc')
36 files changed, 10894 insertions, 0 deletions
diff --git a/src/tspi/rpc/hosttable.c b/src/tspi/rpc/hosttable.c new file mode 100644 index 0000000..f3ec2eb --- /dev/null +++ b/src/tspi/rpc/hosttable.c @@ -0,0 +1,182 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004 + * + */ + + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "trousers/tss.h" +#include "trousers_types.h" +#include "tsplog.h" +#include "hosttable.h" +#include "obj.h" + +struct host_table *ht = NULL; + +TSS_RESULT +host_table_init() +{ + ht = calloc(1, sizeof(struct host_table)); + if (ht == NULL) { + LogError("malloc of %zd bytes failed.", sizeof(struct host_table)); + return TSPERR(TSS_E_OUTOFMEMORY); + } + + MUTEX_INIT(ht->lock); + + return TSS_SUCCESS; +} + +#ifdef SOLARIS +#pragma init(_init) +void _init(void) +#else +void __attribute__ ((constructor)) my_init(void) +#endif +{ + host_table_init(); + __tspi_obj_list_init(); +} + +void +host_table_final() +{ + struct host_table_entry *hte, *next = NULL; + + MUTEX_LOCK(ht->lock); + + for (hte = ht->entries; hte; hte = next) { + if (hte) + next = hte->next; + if (hte->hostname) + free(hte->hostname); + if (hte->comm.buf) + free(hte->comm.buf); + free(hte); + } + + MUTEX_UNLOCK(ht->lock); + + free(ht); + ht = NULL; +} + +#ifdef SOLARIS +#pragma fini(_fini) +void _fini(void) +#else +void __attribute__ ((destructor)) my_fini(void) +#endif +{ + host_table_final(); +} + +TSS_RESULT +__tspi_add_table_entry(TSS_HCONTEXT tspContext, BYTE *host, int type, struct host_table_entry **ret) +{ + struct host_table_entry *entry, *tmp; + + entry = calloc(1, sizeof(struct host_table_entry)); + if (entry == NULL) { + LogError("malloc of %zd bytes failed.", sizeof(struct host_table_entry)); + return TSPERR(TSS_E_OUTOFMEMORY); + } + + entry->tspContext = tspContext; + entry->hostname = host; + entry->type = type; + entry->comm.buf_size = TCSD_INIT_TXBUF_SIZE; + entry->comm.buf = calloc(1, entry->comm.buf_size); + if (entry->comm.buf == NULL) { + LogError("malloc of %u bytes failed.", entry->comm.buf_size); + free(entry); + return TSPERR(TSS_E_OUTOFMEMORY); + } + MUTEX_INIT(entry->lock); + + MUTEX_LOCK(ht->lock); + + for (tmp = ht->entries; tmp; tmp = tmp->next) { + if (tmp->tspContext == tspContext) { + LogError("Tspi_Context_Connect attempted on an already connected context!"); + MUTEX_UNLOCK(ht->lock); + free(entry->hostname); + free(entry->comm.buf); + free(entry); + return TSPERR(TSS_E_CONNECTION_FAILED); + } + } + + if( ht->entries == NULL ) { + ht->entries = entry; + } else { + for (tmp = ht->entries; tmp->next; tmp = tmp->next) + ; + tmp->next = entry; + } + MUTEX_UNLOCK(ht->lock); + + *ret = entry; + + return TSS_SUCCESS; +} + +void +remove_table_entry(TSS_HCONTEXT tspContext) +{ + struct host_table_entry *hte, *prev = NULL; + + MUTEX_LOCK(ht->lock); + + for (hte = ht->entries; hte; prev = hte, hte = hte->next) { + if (hte->tspContext == tspContext) { + if (prev != NULL) + prev->next = hte->next; + else + ht->entries = hte->next; + if (hte->hostname) + free(hte->hostname); + free(hte->comm.buf); + free(hte); + break; + } + } + + MUTEX_UNLOCK(ht->lock); +} + +struct host_table_entry * +get_table_entry(TSS_HCONTEXT tspContext) +{ + struct host_table_entry *index = NULL; + + MUTEX_LOCK(ht->lock); + + for (index = ht->entries; index; index = index->next) { + if (index->tspContext == tspContext) + break; + } + + if (index) + MUTEX_LOCK(index->lock); + + MUTEX_UNLOCK(ht->lock); + + return index; +} + +void +put_table_entry(struct host_table_entry *entry) +{ + if (entry) + MUTEX_UNLOCK(entry->lock); +} + diff --git a/src/tspi/rpc/tcs_api.c b/src/tspi/rpc/tcs_api.c new file mode 100644 index 0000000..3eeb1fb --- /dev/null +++ b/src/tspi/rpc/tcs_api.c @@ -0,0 +1,3377 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004, 2007 + * + */ + + +#include <stdlib.h> +#include <syslog.h> +#include <unistd.h> + +#include "trousers/tss.h" +#include "trousers_types.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "hosttable.h" +#include "tsplog.h" +#include "rpc_tcstp_tsp.h" +#include "obj_context.h" + + +TSS_RESULT +RPC_Error(TSS_HCONTEXT tspContext, ...) +{ + LogDebugFn("Context: 0x%x", tspContext); + return TSPERR(TSS_E_INTERNAL_ERROR); +} + +TSS_RESULT +RPC_OpenContext(TSS_HCONTEXT tspContext, BYTE *hostname, int type) +{ + TSS_RESULT result; + TCS_CONTEXT_HANDLE tcsContext; + struct host_table_entry *entry; + UINT32 tpm_version; + + /* __tspi_add_table_entry() will make sure an entry doesn't already exist for this tsp context */ + if ((result = __tspi_add_table_entry(tspContext, hostname, type, &entry))) + return result; + + switch (type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + if ((result = RPC_OpenContext_TP(entry, &tpm_version, &tcsContext))) + remove_table_entry(tspContext); + else { + entry->tcsContext = tcsContext; + if (obj_context_set_tpm_version(tspContext, tpm_version)) { + remove_table_entry(tspContext); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + return result; + default: + break; + } + + return TSPERR(TSS_E_INTERNAL_ERROR); +} + +TSS_RESULT RPC_GetRegisteredKeyByPublicInfo(TSS_HCONTEXT tspContext, + TCPA_ALGORITHM_ID algID, /* in */ + UINT32 ulPublicInfoLength, /* in */ + BYTE * rgbPublicInfo, /* in */ + UINT32 * keySize, BYTE ** keyBlob) +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetRegisteredKeyByPublicInfo_TP(entry, algID, + ulPublicInfoLength, + rgbPublicInfo, keySize, + keyBlob); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_CloseContext(TSS_HCONTEXT tspContext) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + if ((result = RPC_CloseContext_TP(entry)) == TSS_SUCCESS) { + close(entry->socket); + remove_table_entry(tspContext); + } + break; + default: + break; + } + + if (result != TSS_SUCCESS) + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_FreeMemory(TSS_HCONTEXT tspContext, /* in */ + BYTE * pMemory) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_FreeMemory_TP(entry, pMemory); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_LogPcrEvent(TSS_HCONTEXT tspContext, /* in */ + TSS_PCR_EVENT Event, /* in */ + UINT32 * pNumber) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_LogPcrEvent_TP(entry, Event, pNumber); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_GetPcrEvent(TSS_HCONTEXT tspContext, /* in */ + UINT32 PcrIndex, /* in */ + UINT32 * pNumber, /* in, out */ + TSS_PCR_EVENT ** ppEvent) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = + RPC_GetPcrEvent_TP(entry, PcrIndex, pNumber, ppEvent); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_GetPcrEventsByPcr(TSS_HCONTEXT tspContext, /* in */ + UINT32 PcrIndex, /* in */ + UINT32 FirstEvent, /* in */ + UINT32 * pEventCount, /* in,out */ + TSS_PCR_EVENT ** ppEvents) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetPcrEventsByPcr_TP(entry, PcrIndex, FirstEvent, + pEventCount, ppEvents); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_GetPcrEventLog(TSS_HCONTEXT tspContext, /* in */ + UINT32 * pEventCount, /* out */ + TSS_PCR_EVENT ** ppEvents) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetPcrEventLog_TP(entry, pEventCount, ppEvents); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_RegisterKey(TSS_HCONTEXT tspContext, /* 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_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_RegisterKey_TP(entry, WrappingKeyUUID, KeyUUID, cKeySize, + rgbKey, cVendorData, gbVendorData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_UnregisterKey(TSS_HCONTEXT tspContext, /* in */ + TSS_UUID KeyUUID) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_UnregisterKey_TP(entry, KeyUUID); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_EnumRegisteredKeys(TSS_HCONTEXT tspContext, /* in */ + TSS_UUID * pKeyUUID, /* in */ + UINT32 * pcKeyHierarchySize, /* out */ + TSS_KM_KEYINFO ** ppKeyHierarchy) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_EnumRegisteredKeys_TP(entry, pKeyUUID, pcKeyHierarchySize, + ppKeyHierarchy); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_EnumRegisteredKeys2(TSS_HCONTEXT tspContext, /* in */ + TSS_UUID * pKeyUUID, /* in */ + UINT32 * pcKeyHierarchySize, /* out */ + TSS_KM_KEYINFO2 ** ppKeyHierarchy) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_EnumRegisteredKeys2_TP(entry, pKeyUUID, pcKeyHierarchySize, + ppKeyHierarchy); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + + +TSS_RESULT RPC_GetRegisteredKey(TSS_HCONTEXT tspContext, /* in */ + TSS_UUID KeyUUID, /* in */ + TSS_KM_KEYINFO ** ppKeyInfo) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetRegisteredKey_TP(entry, KeyUUID, ppKeyInfo); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_GetRegisteredKeyBlob(TSS_HCONTEXT tspContext, /* in */ + TSS_UUID KeyUUID, /* in */ + UINT32 * pcKeySize, /* out */ + BYTE ** prgbKey) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetRegisteredKeyBlob_TP(entry, KeyUUID, pcKeySize, prgbKey); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_LoadKeyByBlob(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE hUnwrappingKey, /* in */ + UINT32 cWrappedKeyBlobSize, /* in */ + BYTE * rgbWrappedKeyBlob, /* in */ + TPM_AUTH * pAuth, /* in, out */ + TCS_KEY_HANDLE * phKeyTCSI, /* out */ + TCS_KEY_HANDLE * phKeyHMAC) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_LoadKeyByBlob_TP(entry, hUnwrappingKey, cWrappedKeyBlobSize, + rgbWrappedKeyBlob, pAuth, phKeyTCSI, + phKeyHMAC); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_LoadKeyByUUID(TSS_HCONTEXT tspContext, /* in */ + TSS_UUID KeyUUID, /* in */ + TCS_LOADKEY_INFO * pLoadKeyInfo, /* in, out */ + TCS_KEY_HANDLE * phKeyTCSI) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_LoadKeyByUUID_TP(entry, KeyUUID, pLoadKeyInfo, phKeyTCSI); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_EvictKey(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE hKey) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_EvictKey_TP(entry, hKey); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_CreateWrapKey(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE hWrappingKey, /* in */ + TCPA_ENCAUTH *KeyUsageAuth, /* in */ + TCPA_ENCAUTH *KeyMigrationAuth, /* in */ + UINT32 keyInfoSize, /* in */ + BYTE * keyInfo, /* in */ + UINT32 * keyDataSize, /* out */ + BYTE ** keyData, /* out */ + TPM_AUTH * pAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CreateWrapKey_TP(entry, hWrappingKey, KeyUsageAuth, + KeyMigrationAuth, keyInfoSize, keyInfo, + keyDataSize, keyData, pAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_GetPubKey(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE hKey, /* in */ + TPM_AUTH * pAuth, /* in, out */ + UINT32 * pcPubKeySize, /* out */ + BYTE ** prgbPubKey) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetPubKey_TP(entry, hKey, pAuth, pcPubKeySize, prgbPubKey); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_MakeIdentity(TSS_HCONTEXT tspContext, /* in */ + TCPA_ENCAUTH identityAuth, /* in */ + TCPA_CHOSENID_HASH IDLabel_PrivCAHash, /* in */ + UINT32 idKeyInfoSize, /* in */ + BYTE * idKeyInfo, /* in */ + TPM_AUTH * pSrkAuth, /* in, out */ + TPM_AUTH * pOwnerAuth, /* in, out */ + UINT32 * idKeySize, /* out */ + BYTE ** idKey, /* out */ + UINT32 * pcIdentityBindingSize, /* out */ + BYTE ** prgbIdentityBinding, /* out */ + UINT32 * pcEndorsementCredentialSize, /* out */ + BYTE ** prgbEndorsementCredential, /* out */ + UINT32 * pcPlatformCredentialSize, /* out */ + BYTE ** prgbPlatformCredential, /* out */ + UINT32 * pcConformanceCredentialSize, /* out */ + BYTE ** prgbConformanceCredential) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_MakeIdentity_TP(entry, identityAuth, + IDLabel_PrivCAHash, idKeyInfoSize, idKeyInfo, + pSrkAuth, pOwnerAuth, idKeySize, idKey, + pcIdentityBindingSize, prgbIdentityBinding, + pcEndorsementCredentialSize, + prgbEndorsementCredential, + pcPlatformCredentialSize, + prgbPlatformCredential, + pcConformanceCredentialSize, + prgbConformanceCredential); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +#ifdef TSS_BUILD_TSS12 +TSS_RESULT RPC_GetCredential(TSS_HCONTEXT tspContext, /* in */ + UINT32 ulCredentialType, /* in */ + UINT32 ulCredentialAccessMode, /* in */ + UINT32 * pulCredentialSize, /* out */ + BYTE ** prgbCredentialData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetCredential_TP(entry, ulCredentialType, + ulCredentialAccessMode, pulCredentialSize, + prgbCredentialData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +TSS_RESULT RPC_SetOwnerInstall(TSS_HCONTEXT tspContext, /* in */ + TSS_BOOL state) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_SetOwnerInstall_TP(entry, state); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_TakeOwnership(TSS_HCONTEXT tspContext, /* in */ + UINT16 protocolID, /* in */ + UINT32 encOwnerAuthSize, /* in */ + BYTE * encOwnerAuth, /* in */ + UINT32 encSrkAuthSize, /* in */ + BYTE * encSrkAuth, /* in */ + UINT32 srkInfoSize, /* in */ + BYTE * srkInfo, /* in */ + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * srkKeySize, + BYTE ** srkKey) +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_TakeOwnership_TP(entry, protocolID, + encOwnerAuthSize, encOwnerAuth, + encSrkAuthSize, encSrkAuth, srkInfoSize, + srkInfo, ownerAuth, srkKeySize, srkKey); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_OIAP(TSS_HCONTEXT tspContext, /* in */ + TCS_AUTHHANDLE * authHandle, /* out */ + TCPA_NONCE * nonce0) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_OIAP_TP(entry, authHandle, nonce0); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_OSAP(TSS_HCONTEXT tspContext, /* in */ + TCPA_ENTITY_TYPE entityType, /* in */ + UINT32 entityValue, /* in */ + TPM_NONCE *nonceOddOSAP, /* in */ + TCS_AUTHHANDLE * authHandle, /* out */ + TCPA_NONCE * nonceEven, /* out */ + TCPA_NONCE * nonceEvenOSAP) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_OSAP_TP(entry, entityType, entityValue, nonceOddOSAP, + authHandle, nonceEven, nonceEvenOSAP); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_ChangeAuth(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE parentHandle, /* in */ + TCPA_PROTOCOL_ID protocolID, /* in */ + TCPA_ENCAUTH *newAuth, /* in */ + TCPA_ENTITY_TYPE entityType, /* in */ + UINT32 encDataSize, /* in */ + BYTE * encData, /* in */ + TPM_AUTH * ownerAuth, /* in, out */ + TPM_AUTH * entityAuth, /* in, out */ + UINT32 * outDataSize, /* out */ + BYTE ** outData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ChangeAuth_TP(entry, parentHandle, protocolID, newAuth, + entityType, encDataSize, encData, ownerAuth, + entityAuth, outDataSize, outData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_ChangeAuthOwner(TSS_HCONTEXT tspContext, /* in */ + TCPA_PROTOCOL_ID protocolID, /* in */ + TCPA_ENCAUTH *newAuth, /* in */ + TCPA_ENTITY_TYPE entityType, /* in */ + TPM_AUTH * ownerAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ChangeAuthOwner_TP(entry, protocolID, newAuth, entityType, + ownerAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_ChangeAuthAsymStart(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE idHandle, /* in */ + TCPA_NONCE antiReplay, /* in */ + UINT32 KeySizeIn, /* in */ + BYTE * KeyDataIn, /* in */ + TPM_AUTH * pAuth, /* in, out */ + UINT32 * KeySizeOut, /* out */ + BYTE ** KeyDataOut, /* out */ + UINT32 * CertifyInfoSize, /* out */ + BYTE ** CertifyInfo, /* out */ + UINT32 * sigSize, /* out */ + BYTE ** sig, /* out */ + TCS_KEY_HANDLE * ephHandle) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ChangeAuthAsymStart_TP(entry, idHandle, antiReplay, + KeySizeIn, KeyDataIn, pAuth, + KeySizeOut, KeyDataOut, + CertifyInfoSize, CertifyInfo, sigSize, + sig, ephHandle); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_ChangeAuthAsymFinish(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE parentHandle, /* in */ + TCS_KEY_HANDLE ephHandle, /* in */ + TCPA_ENTITY_TYPE entityType, /* in */ + TCPA_HMAC newAuthLink, /* in */ + UINT32 newAuthSize, /* in */ + BYTE * encNewAuth, /* in */ + UINT32 encDataSizeIn, /* in */ + BYTE * encDataIn, /* in */ + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * encDataSizeOut, /* out */ + BYTE ** encDataOut, /* out */ + TCPA_SALT_NONCE * saltNonce, /* out */ + TCPA_DIGEST * changeProof) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ChangeAuthAsymFinish_TP(entry, parentHandle, ephHandle, + entityType, newAuthLink, + newAuthSize, encNewAuth, + encDataSizeIn, encDataIn, ownerAuth, + encDataSizeOut, encDataOut, saltNonce, + changeProof); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_TerminateHandle(TSS_HCONTEXT tspContext, /* in */ + TCS_AUTHHANDLE handle) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_TerminateHandle_TP(entry, handle); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_ActivateTPMIdentity(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE idKey, /* in */ + UINT32 blobSize, /* in */ + BYTE * blob, /* in */ + TPM_AUTH * idKeyAuth, /* in, out */ + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * SymmetricKeySize, /* out */ + BYTE ** SymmetricKey) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ActivateTPMIdentity_TP(entry, idKey, blobSize, blob, idKeyAuth, + ownerAuth, SymmetricKeySize, + SymmetricKey); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_Extend(TSS_HCONTEXT tspContext, /* in */ + TCPA_PCRINDEX pcrNum, /* in */ + TCPA_DIGEST inDigest, /* in */ + TCPA_PCRVALUE * outDigest) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Extend_TP(entry, pcrNum, inDigest, outDigest); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_PcrRead(TSS_HCONTEXT tspContext, /* in */ + TCPA_PCRINDEX pcrNum, /* in */ + TCPA_PCRVALUE * outDigest) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_PcrRead_TP(entry, pcrNum, outDigest); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_PcrReset(TSS_HCONTEXT tspContext, /* in */ + UINT32 pcrDataSizeIn, /* in */ + BYTE * pcrDataIn) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_PcrReset_TP(entry, pcrDataSizeIn, pcrDataIn); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + + +TSS_RESULT RPC_Quote(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + TCPA_NONCE *antiReplay, /* in */ + UINT32 pcrDataSizeIn, /* in */ + BYTE * pcrDataIn, /* in */ + TPM_AUTH * privAuth, /* in, out */ + UINT32 * pcrDataSizeOut, /* out */ + BYTE ** pcrDataOut, /* out */ + UINT32 * sigSize, /* out */ + BYTE ** sig) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Quote_TP(entry, keyHandle, antiReplay, pcrDataSizeIn, + pcrDataIn, privAuth, pcrDataSizeOut, pcrDataOut, + sigSize, sig); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +#ifdef TSS_BUILD_TSS12 +TSS_RESULT RPC_Quote2(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + TCPA_NONCE *antiReplay, /* in */ + UINT32 pcrDataSizeIn, /* in */ + BYTE * pcrDataIn, /* in */ + TSS_BOOL addVersion, /* in */ + TPM_AUTH * privAuth, /* in,out */ + UINT32 * pcrDataSizeOut, /* out */ + BYTE ** pcrDataOut, /* out */ + UINT32 * versionInfoSize, /* out */ + BYTE ** versionInfo, /* out */ + UINT32 * sigSize, /* out */ + BYTE ** sig) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Quote2_TP(entry, keyHandle, antiReplay, pcrDataSizeIn, pcrDataIn, + addVersion,privAuth, pcrDataSizeOut, pcrDataOut, + versionInfoSize, versionInfo,sigSize, sig); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +TSS_RESULT RPC_DirWriteAuth(TSS_HCONTEXT tspContext, /* in */ + TCPA_DIRINDEX dirIndex, /* in */ + TCPA_DIRVALUE *newContents, /* in */ + TPM_AUTH * ownerAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_DirWriteAuth_TP(entry, dirIndex, newContents, ownerAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_DirRead(TSS_HCONTEXT tspContext, /* in */ + TCPA_DIRINDEX dirIndex, /* in */ + TCPA_DIRVALUE * dirValue) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_DirRead_TP(entry, dirIndex, dirValue); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_Seal(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + TCPA_ENCAUTH *encAuth, /* in */ + UINT32 pcrInfoSize, /* in */ + BYTE * PcrInfo, /* in */ + UINT32 inDataSize, /* in */ + BYTE * inData, /* in */ + TPM_AUTH * pubAuth, /* in, out */ + UINT32 * SealedDataSize, /* out */ + BYTE ** SealedData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Seal_TP(entry, keyHandle, encAuth, pcrInfoSize, PcrInfo, + inDataSize, inData, pubAuth, SealedDataSize, + SealedData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +#ifdef TSS_BUILD_SEALX +TSS_RESULT RPC_Sealx(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + TCPA_ENCAUTH *encAuth, /* in */ + UINT32 pcrInfoSize, /* in */ + BYTE * PcrInfo, /* in */ + UINT32 inDataSize, /* in */ + BYTE * inData, /* in */ + TPM_AUTH * pubAuth, /* in, out */ + UINT32 * SealedDataSize, /* out */ + BYTE ** SealedData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Sealx_TP(entry, keyHandle, encAuth, pcrInfoSize, PcrInfo, + inDataSize, inData, pubAuth, SealedDataSize, + SealedData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +TSS_RESULT RPC_Unseal(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE parentHandle, /* in */ + UINT32 SealedDataSize, /* in */ + BYTE * SealedData, /* in */ + TPM_AUTH * parentAuth, /* in, out */ + TPM_AUTH * dataAuth, /* in, out */ + UINT32 * DataSize, /* out */ + BYTE ** Data) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Unseal_TP(entry, parentHandle, SealedDataSize, SealedData, + parentAuth, dataAuth, DataSize, Data); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_UnBind(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + UINT32 inDataSize, /* in */ + BYTE * inData, /* in */ + TPM_AUTH * privAuth, /* in, out */ + UINT32 * outDataSize, /* out */ + BYTE ** outData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_UnBind_TP(entry, keyHandle, inDataSize, inData, privAuth, + outDataSize, outData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_CreateMigrationBlob(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE parentHandle, /* in */ + TCPA_MIGRATE_SCHEME migrationType, /* in */ + UINT32 MigrationKeyAuthSize, /* in */ + BYTE * MigrationKeyAuth, /* in */ + UINT32 encDataSize, /* in */ + BYTE * encData, /* in */ + TPM_AUTH * parentAuth, /* in, out */ + TPM_AUTH * entityAuth, /* in, out */ + UINT32 * randomSize, /* out */ + BYTE ** random, /* out */ + UINT32 * outDataSize, /* out */ + BYTE ** outData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CreateMigrationBlob_TP(entry, parentHandle, + migrationType, MigrationKeyAuthSize, + MigrationKeyAuth, encDataSize, encData, + parentAuth, entityAuth, randomSize, + random, outDataSize, outData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_ConvertMigrationBlob(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE parentHandle, /* in */ + UINT32 inDataSize, /* in */ + BYTE * inData, /* in */ + UINT32 randomSize, /* in */ + BYTE * random, /* in */ + TPM_AUTH * parentAuth, /* in, out */ + UINT32 * outDataSize, /* out */ + BYTE ** outData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ConvertMigrationBlob_TP(entry, parentHandle, + inDataSize, inData, randomSize, + random, parentAuth, outDataSize, + outData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_AuthorizeMigrationKey(TSS_HCONTEXT tspContext, /* in */ + TCPA_MIGRATE_SCHEME migrateScheme, /* in */ + UINT32 MigrationKeySize, /* in */ + BYTE * MigrationKey, /* in */ + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * MigrationKeyAuthSize, /* out */ + BYTE ** MigrationKeyAuth) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_AuthorizeMigrationKey_TP(entry, migrateScheme, + MigrationKeySize, MigrationKey, + ownerAuth, MigrationKeyAuthSize, + MigrationKeyAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_CertifyKey(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE certHandle, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + TPM_NONCE * antiReplay, /* in */ + TPM_AUTH * certAuth, /* in, out */ + TPM_AUTH * keyAuth, /* in, out */ + UINT32 * CertifyInfoSize, /* out */ + BYTE ** CertifyInfo, /* out */ + UINT32 * outDataSize, /* out */ + BYTE ** outData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CertifyKey_TP(entry, certHandle, keyHandle, antiReplay, + certAuth, keyAuth, CertifyInfoSize, CertifyInfo, + outDataSize, outData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_Sign(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + UINT32 areaToSignSize, /* in */ + BYTE * areaToSign, /* in */ + TPM_AUTH * privAuth, /* in, out */ + UINT32 * sigSize, /* out */ + BYTE ** sig) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Sign_TP(entry, keyHandle, areaToSignSize, areaToSign, privAuth, + sigSize, sig); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_GetRandom(TSS_HCONTEXT tspContext, /* in */ + UINT32 bytesRequested, /* in */ + BYTE ** randomBytes) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetRandom_TP(entry, bytesRequested, randomBytes); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_StirRandom(TSS_HCONTEXT tspContext, /* in */ + UINT32 inDataSize, /* in */ + BYTE * inData) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_StirRandom_TP(entry, inDataSize, inData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_GetTPMCapability(TSS_HCONTEXT tspContext, /* in */ + TCPA_CAPABILITY_AREA capArea, /* in */ + UINT32 subCapSize, /* in */ + BYTE * subCap, /* in */ + UINT32 * respSize, /* out */ + BYTE ** resp) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetTPMCapability_TP(entry, capArea, subCapSize, subCap, + respSize, resp); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_SetCapability(TSS_HCONTEXT tspContext, /* in */ + TCPA_CAPABILITY_AREA capArea, /* in */ + UINT32 subCapSize, /* in */ + BYTE * subCap, /* in */ + UINT32 valueSize, /* in */ + BYTE * value, /* in */ + TPM_AUTH *ownerAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_SetCapability_TP(entry, capArea, subCapSize, subCap, + valueSize, value, ownerAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_GetCapability(TSS_HCONTEXT tspContext, /* in */ + TCPA_CAPABILITY_AREA capArea, /* in */ + UINT32 subCapSize, /* in */ + BYTE * subCap, /* in */ + UINT32 * respSize, /* out */ + BYTE ** resp) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetCapability_TP(entry, capArea, subCapSize, subCap, respSize, + resp); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_GetCapabilitySigned(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + TCPA_NONCE antiReplay, /* in */ + TCPA_CAPABILITY_AREA capArea, /* in */ + UINT32 subCapSize, /* in */ + BYTE * subCap, /* in */ + TPM_AUTH * privAuth, /* in, out */ + TCPA_VERSION * Version, /* out */ + UINT32 * respSize, /* out */ + BYTE ** resp, /* out */ + UINT32 * sigSize, /* out */ + BYTE ** sig) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetCapabilitySigned_TP(entry, keyHandle, antiReplay, capArea, + subCapSize, subCap, privAuth, Version, + respSize, resp, sigSize, sig); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_GetCapabilityOwner(TSS_HCONTEXT tspContext, /* in */ + TPM_AUTH * pOwnerAuth, /* out */ + TCPA_VERSION * pVersion, /* out */ + UINT32 * pNonVolatileFlags, /* out */ + UINT32 * pVolatileFlags) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetCapabilityOwner_TP(entry, pOwnerAuth, pVersion, + pNonVolatileFlags, pVolatileFlags); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_CreateEndorsementKeyPair(TSS_HCONTEXT tspContext, /* in */ + TCPA_NONCE antiReplay, /* in */ + UINT32 endorsementKeyInfoSize, /* in */ + BYTE * endorsementKeyInfo, /* in */ + UINT32 * endorsementKeySize, /* out */ + BYTE ** endorsementKey, /* out */ + TCPA_DIGEST * checksum) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CreateEndorsementKeyPair_TP(entry, antiReplay, + endorsementKeyInfoSize, + endorsementKeyInfo, + endorsementKeySize, + endorsementKey, checksum); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_ReadPubek(TSS_HCONTEXT tspContext, /* in */ + TCPA_NONCE antiReplay, /* in */ + UINT32 * pubEndorsementKeySize, /* out */ + BYTE ** pubEndorsementKey, /* out */ + TCPA_DIGEST * checksum) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ReadPubek_TP(entry, antiReplay, pubEndorsementKeySize, + pubEndorsementKey, checksum); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_DisablePubekRead(TSS_HCONTEXT tspContext, /* in */ + TPM_AUTH * ownerAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_DisablePubekRead_TP(entry, ownerAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_OwnerReadPubek(TSS_HCONTEXT tspContext, /* in */ + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * pubEndorsementKeySize, /* out */ + BYTE ** pubEndorsementKey) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_OwnerReadPubek_TP(entry, ownerAuth, pubEndorsementKeySize, + pubEndorsementKey); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +#ifdef TSS_BUILD_TSS12 +TSS_RESULT RPC_CreateRevocableEndorsementKeyPair(TSS_HCONTEXT tspContext, /* in */ + TPM_NONCE antiReplay, /* in */ + UINT32 endorsementKeyInfoSize,/* in */ + BYTE * endorsementKeyInfo, /* in */ + TSS_BOOL genResetAuth, /* in */ + TPM_DIGEST * eKResetAuth, /* in, out */ + UINT32 * endorsementKeySize, /* out */ + BYTE ** endorsementKey, /* out */ + TPM_DIGEST * checksum) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CreateRevocableEndorsementKeyPair_TP(entry, antiReplay, + endorsementKeyInfoSize, + endorsementKeyInfo, + genResetAuth, + eKResetAuth, + endorsementKeySize, + endorsementKey, checksum); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_RevokeEndorsementKeyPair(TSS_HCONTEXT tspContext, /* in */ + TPM_DIGEST *EKResetAuth) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_RevokeEndorsementKeyPair_TP(entry, EKResetAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +TSS_RESULT RPC_SelfTestFull(TSS_HCONTEXT tspContext) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_SelfTestFull_TP(entry); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_CertifySelfTest(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + TCPA_NONCE antiReplay, /* in */ + TPM_AUTH * privAuth, /* in, out */ + UINT32 * sigSize, /* out */ + BYTE ** sig) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CertifySelfTest_TP(entry, keyHandle, antiReplay, privAuth, + sigSize, sig); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_GetTestResult(TSS_HCONTEXT tspContext, /* in */ + UINT32 * outDataSize, /* out */ + BYTE ** outData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetTestResult_TP(entry, outDataSize, outData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_OwnerSetDisable(TSS_HCONTEXT tspContext, /* in */ + TSS_BOOL disableState, /* in */ + TPM_AUTH * ownerAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_OwnerSetDisable_TP(entry, disableState, ownerAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +#ifdef TSS_BUILD_TSS12 +TSS_RESULT RPC_ResetLockValue(TSS_HCONTEXT tspContext, /* in */ + TPM_AUTH * ownerAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ResetLockValue_TP(entry, ownerAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +TSS_RESULT RPC_OwnerClear(TSS_HCONTEXT tspContext, /* in */ + TPM_AUTH * ownerAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_OwnerClear_TP(entry, ownerAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_DisableOwnerClear(TSS_HCONTEXT tspContext, /* in */ + TPM_AUTH * ownerAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_DisableOwnerClear_TP(entry, ownerAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_ForceClear(TSS_HCONTEXT tspContext) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ForceClear_TP(entry); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_DisableForceClear(TSS_HCONTEXT tspContext) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_DisableForceClear_TP(entry); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_PhysicalDisable(TSS_HCONTEXT tspContext) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_PhysicalDisable_TP(entry); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_PhysicalEnable(TSS_HCONTEXT tspContext) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_PhysicalEnable_TP(entry); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_PhysicalSetDeactivated(TSS_HCONTEXT tspContext, /* in */ + TSS_BOOL state) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_PhysicalSetDeactivated_TP(entry, state); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_PhysicalPresence(TSS_HCONTEXT tspContext, /* in */ + TCPA_PHYSICAL_PRESENCE fPhysicalPresence) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_PhysicalPresence_TP(entry, fPhysicalPresence); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_SetTempDeactivated(TSS_HCONTEXT tspContext) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_SetTempDeactivated_TP(entry); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +#ifdef TSS_BUILD_TSS12 +TSS_RESULT RPC_SetTempDeactivated2(TSS_HCONTEXT tspContext, /* in */ + TPM_AUTH *operatorAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_SetTempDeactivated2_TP(entry, operatorAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +TSS_RESULT RPC_FieldUpgrade(TSS_HCONTEXT tspContext, /* in */ + UINT32 dataInSize, /* in */ + BYTE * dataIn, /* in */ + UINT32 * dataOutSize, /* out */ + BYTE ** dataOut, /* out */ + TPM_AUTH * ownerAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = (UINT32) TSPERR(TSS_E_INTERNAL_ERROR); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_SetRedirection(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + UINT32 c1, /* in */ + UINT32 c2, /* in */ + TPM_AUTH * privAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = (UINT32) TSPERR(TSS_E_INTERNAL_ERROR); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_CreateMaintenanceArchive(TSS_HCONTEXT tspContext, /* in */ + TSS_BOOL generateRandom, /* in */ + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * randomSize, /* out */ + BYTE ** random, /* out */ + UINT32 * archiveSize, /* out */ + BYTE ** archive) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CreateMaintenanceArchive_TP(entry, generateRandom, ownerAuth, + randomSize, random, archiveSize, + archive); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_LoadMaintenanceArchive(TSS_HCONTEXT tspContext, /* in */ + UINT32 dataInSize, /* in */ + BYTE * dataIn, /* in */ + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * dataOutSize, /* out */ + BYTE ** dataOut) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_LoadMaintenanceArchive_TP(entry, dataInSize, dataIn, ownerAuth, + dataOutSize, dataOut); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_KillMaintenanceFeature(TSS_HCONTEXT tspContext, /* in */ + TPM_AUTH * ownerAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_KillMaintenanceFeature_TP(entry, ownerAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_LoadManuMaintPub(TSS_HCONTEXT tspContext, /* in */ + TCPA_NONCE antiReplay, /* in */ + UINT32 PubKeySize, /* in */ + BYTE * PubKey, /* in */ + TCPA_DIGEST * checksum) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_LoadManuMaintPub_TP(entry, antiReplay, PubKeySize, PubKey, + checksum); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT RPC_ReadManuMaintPub(TSS_HCONTEXT tspContext, /* in */ + TCPA_NONCE antiReplay, /* in */ + TCPA_DIGEST * checksum) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ReadManuMaintPub_TP(entry, antiReplay, checksum); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +#ifdef TSS_BUILD_DAA +TSS_RESULT +RPC_DaaJoin(TSS_HCONTEXT tspContext, /* in */ + TPM_HANDLE daa_session, /* in */ + BYTE stage, /* in */ + UINT32 inputSize0, /* in */ + BYTE* inputData0, /* in */ + UINT32 inputSize1, /* in */ + BYTE* inputData1, /* in */ + TPM_AUTH* ownerAuth, /* in, out */ + UINT32* outputSize, /* out */ + BYTE** outputData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_DaaJoin_TP(entry, daa_session, stage, inputSize0, inputData0, + inputSize1, inputData1, ownerAuth, outputSize, + outputData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; + +} + +TSS_RESULT +RPC_DaaSign(TSS_HCONTEXT tspContext, /* in */ + TPM_HANDLE daa_session, /* in */ + BYTE stage, /* in */ + UINT32 inputSize0, /* in */ + BYTE* inputData0, /* in */ + UINT32 inputSize1, /* in */ + BYTE* inputData1, /* in */ + TPM_AUTH* ownerAuth, /* in, out */ + UINT32* outputSize, /* out */ + BYTE** outputData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_DaaSign_TP(entry, daa_session, stage, inputSize0, inputData0, + inputSize1, inputData1, ownerAuth, outputSize, + outputData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +#ifdef TSS_BUILD_COUNTER +TSS_RESULT +RPC_ReadCounter(TSS_HCONTEXT tspContext, /* in */ + TSS_COUNTER_ID idCounter, /* in */ + TPM_COUNTER_VALUE* counterValue) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ReadCounter_TP(entry, idCounter, counterValue); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_CreateCounter(TSS_HCONTEXT tspContext, /* in */ + UINT32 LabelSize, /* in (=4) */ + BYTE* pLabel, /* in */ + TPM_ENCAUTH CounterAuth, /* in */ + TPM_AUTH* pOwnerAuth, /* in, out */ + TSS_COUNTER_ID* idCounter, /* out */ + TPM_COUNTER_VALUE* counterValue) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CreateCounter_TP(entry, LabelSize, pLabel, CounterAuth, + pOwnerAuth, idCounter, counterValue); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_IncrementCounter(TSS_HCONTEXT tspContext, /* in */ + TSS_COUNTER_ID idCounter, /* in */ + TPM_AUTH* pCounterAuth, /* in, out */ + TPM_COUNTER_VALUE* counterValue) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_IncrementCounter_TP(entry, idCounter, pCounterAuth, + counterValue); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_ReleaseCounter(TSS_HCONTEXT tspContext, /* in */ + TSS_COUNTER_ID idCounter, /* in */ + TPM_AUTH* pCounterAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ReleaseCounter_TP(entry, idCounter, pCounterAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_ReleaseCounterOwner(TSS_HCONTEXT tspContext, /* in */ + TSS_COUNTER_ID idCounter, /* in */ + TPM_AUTH* pOwnerAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ReleaseCounterOwner_TP(entry, idCounter, pOwnerAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +#ifdef TSS_BUILD_TICK +TSS_RESULT +RPC_ReadCurrentTicks(TSS_HCONTEXT tspContext, /* in */ + UINT32* pulCurrentTime, /* out */ + BYTE** prgbCurrentTime) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ReadCurrentTicks_TP(entry, pulCurrentTime, prgbCurrentTime); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_TickStampBlob(TSS_HCONTEXT tspContext, /* in */ + TCS_KEY_HANDLE hKey, /* in */ + TPM_NONCE* antiReplay, /* in */ + TPM_DIGEST* digestToStamp, /* in */ + TPM_AUTH* privAuth, /* in, out */ + UINT32* pulSignatureLength, /* out */ + BYTE** prgbSignature, /* out */ + UINT32* pulTickCountLength, /* out */ + BYTE** prgbTickCount) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_TickStampBlob_TP(entry, hKey, antiReplay, digestToStamp, + privAuth, pulSignatureLength, + prgbSignature, pulTickCountLength, + prgbTickCount); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +#ifdef TSS_BUILD_TRANSPORT +TSS_RESULT +RPC_EstablishTransport(TSS_HCONTEXT tspContext, + UINT32 ulTransControlFlags, + TCS_KEY_HANDLE hEncKey, + UINT32 ulTransSessionInfoSize, + BYTE* rgbTransSessionInfo, + UINT32 ulSecretSize, + BYTE* rgbSecret, + TPM_AUTH* pEncKeyAuth, /* in, out */ + TPM_MODIFIER_INDICATOR* pbLocality, + TCS_HANDLE* hTransSession, + UINT32* ulCurrentTicksSize, + BYTE** prgbCurrentTicks, + TPM_NONCE* pTransNonce) +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_EstablishTransport_TP(entry, ulTransControlFlags, hEncKey, + ulTransSessionInfoSize, + rgbTransSessionInfo, ulSecretSize, + rgbSecret, pEncKeyAuth, pbLocality, + hTransSession, ulCurrentTicksSize, + prgbCurrentTicks, pTransNonce); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + + +TSS_RESULT +RPC_ExecuteTransport(TSS_HCONTEXT tspContext, + TPM_COMMAND_CODE unWrappedCommandOrdinal, + UINT32 ulWrappedCmdParamInSize, + BYTE* rgbWrappedCmdParamIn, + UINT32* pulHandleListSize, /* in, out */ + TCS_HANDLE** rghHandles, /* in, out */ + TPM_AUTH* pWrappedCmdAuth1, /* in, out */ + TPM_AUTH* pWrappedCmdAuth2, /* in, out */ + TPM_AUTH* pTransAuth, /* in, out */ + UINT64* punCurrentTicks, + TPM_MODIFIER_INDICATOR* pbLocality, + TPM_RESULT* pulWrappedCmdReturnCode, + UINT32* ulWrappedCmdParamOutSize, + BYTE** rgbWrappedCmdParamOut) +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ExecuteTransport_TP(entry, unWrappedCommandOrdinal, + ulWrappedCmdParamInSize, + rgbWrappedCmdParamIn, pulHandleListSize, + rghHandles, pWrappedCmdAuth1, + pWrappedCmdAuth2, pTransAuth, + punCurrentTicks, pbLocality, + pulWrappedCmdReturnCode, + ulWrappedCmdParamOutSize, + rgbWrappedCmdParamOut); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_ReleaseTransportSigned(TSS_HCONTEXT tspContext, + TCS_KEY_HANDLE hSignatureKey, + TPM_NONCE* AntiReplayNonce, + TPM_AUTH* pKeyAuth, /* in, out */ + TPM_AUTH* pTransAuth, /* in, out */ + TPM_MODIFIER_INDICATOR* pbLocality, + UINT32* pulCurrentTicksSize, + BYTE** prgbCurrentTicks, + UINT32* pulSignatureSize, + BYTE** prgbSignature) +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(tspContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_ReleaseTransportSigned_TP(entry, hSignatureKey, + AntiReplayNonce, pKeyAuth, + pTransAuth, pbLocality, + pulCurrentTicksSize, + prgbCurrentTicks, pulSignatureSize, + prgbSignature); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +#ifdef TSS_BUILD_NV +TSS_RESULT +RPC_NV_DefineOrReleaseSpace(TSS_HCONTEXT hContext, /* in */ + UINT32 cPubInfoSize, /* in */ + BYTE* pPubInfo, /* in */ + TCPA_ENCAUTH encAuth, /* in */ + TPM_AUTH* pAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_NV_DefineOrReleaseSpace_TP(entry, cPubInfoSize, pPubInfo, + encAuth, pAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_NV_WriteValue(TSS_HCONTEXT hContext, /* in */ + TSS_NV_INDEX hNVStore, /* in */ + UINT32 offset, /* in */ + UINT32 ulDataLength, /* in */ + BYTE* rgbDataToWrite, /* in */ + TPM_AUTH* privAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_NV_WriteValue_TP(entry, hNVStore, offset, ulDataLength, + rgbDataToWrite, privAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + + +TSS_RESULT +RPC_NV_WriteValueAuth(TSS_HCONTEXT hContext, /* in */ + TSS_NV_INDEX hNVStore, /* in */ + UINT32 offset, /* in */ + UINT32 ulDataLength, /* in */ + BYTE* rgbDataToWrite, /* in */ + TPM_AUTH* NVAuth) /* in, out */ +{ + + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_NV_WriteValueAuth_TP(entry, hNVStore, offset, ulDataLength, + rgbDataToWrite, NVAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + + +TSS_RESULT +RPC_NV_ReadValue(TSS_HCONTEXT hContext, /* in */ + TSS_NV_INDEX hNVStore, /* in */ + UINT32 offset, /* in */ + UINT32* pulDataLength, /* in, out */ + TPM_AUTH* privAuth, /* in, out */ + BYTE** rgbDataRead) /* out */ +{ + + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_NV_ReadValue_TP(entry, hNVStore, offset, pulDataLength, + privAuth, rgbDataRead); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_NV_ReadValueAuth(TSS_HCONTEXT hContext, /* in */ + TSS_NV_INDEX hNVStore, /* in */ + UINT32 offset, /* in */ + UINT32* pulDataLength, /* in, out */ + TPM_AUTH* NVAuth, /* in, out */ + BYTE** rgbDataRead) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_NV_ReadValueAuth_TP(entry, hNVStore, offset, pulDataLength, + NVAuth, rgbDataRead); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +#ifdef TSS_BUILD_AUDIT +TSS_RESULT +RPC_SetOrdinalAuditStatus(TSS_HCONTEXT hContext, /* in */ + TPM_AUTH *ownerAuth, /* in/out */ + UINT32 ulOrdinal, /* in */ + TSS_BOOL bAuditState) /* in */ +{ + TSS_RESULT result = TSS_SUCCESS; + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_SetOrdinalAuditStatus_TP(entry, ownerAuth, ulOrdinal, + bAuditState); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_GetAuditDigest(TSS_HCONTEXT hContext, /* in */ + UINT32 startOrdinal, /* in */ + TPM_DIGEST *auditDigest, /* out */ + UINT32 *counterValueSize, /* out */ + BYTE **counterValue, /* out */ + TSS_BOOL *more, /* out */ + UINT32 *ordSize, /* out */ + UINT32 **ordList) /* out */ +{ + TSS_RESULT result = TSS_SUCCESS; + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetAuditDigest_TP(entry, startOrdinal, auditDigest, + counterValueSize, counterValue, more, + ordSize, ordList); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_GetAuditDigestSigned(TSS_HCONTEXT hContext, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + TSS_BOOL closeAudit, /* in */ + TPM_NONCE *antiReplay, /* in */ + TPM_AUTH *privAuth, /* in/out */ + UINT32 *counterValueSize, /* out */ + BYTE **counterValue, /* out */ + TPM_DIGEST *auditDigest, /* out */ + TPM_DIGEST *ordinalDigest, /* out */ + UINT32 *sigSize, /* out */ + BYTE **sig) /* out */ +{ + TSS_RESULT result = TSS_SUCCESS; + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_GetAuditDigestSigned_TP(entry, keyHandle, closeAudit, + antiReplay, privAuth, + counterValueSize, counterValue, + auditDigest, ordinalDigest, + sigSize, sig); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +#ifdef TSS_BUILD_TSS12 +TSS_RESULT +RPC_SetOperatorAuth(TSS_HCONTEXT hContext, /* in */ + TCPA_SECRET *operatorAuth) /* in */ +{ + TSS_RESULT result = TSS_SUCCESS; + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_SetOperatorAuth_TP(entry, operatorAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_OwnerReadInternalPub(TSS_HCONTEXT hContext, /* in */ + TCS_KEY_HANDLE hKey, /* in */ + TPM_AUTH* pOwnerAuth, /* in, out */ + UINT32* punPubKeySize, /* out */ + BYTE** ppbPubKeyData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_OwnerReadInternalPub_TP(entry, hKey, pOwnerAuth, punPubKeySize, + ppbPubKeyData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +#ifdef TSS_BUILD_DELEGATION +TSS_RESULT +RPC_Delegate_Manage(TSS_HCONTEXT hContext, /* in */ + TPM_FAMILY_ID familyID, /* in */ + TPM_FAMILY_OPERATION opFlag, /* in */ + UINT32 opDataSize, /* in */ + BYTE *opData, /* in */ + TPM_AUTH *ownerAuth, /* in, out */ + UINT32 *retDataSize, /* out */ + BYTE **retData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Delegate_Manage_TP(entry, familyID, opFlag, opDataSize, opData, + ownerAuth, retDataSize, retData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_Delegate_CreateKeyDelegation(TSS_HCONTEXT hContext, /* in */ + TCS_KEY_HANDLE hKey, /* in */ + UINT32 publicInfoSize, /* in */ + BYTE *publicInfo, /* in */ + TPM_ENCAUTH *encDelAuth, /* in */ + TPM_AUTH *keyAuth, /* in, out */ + UINT32 *blobSize, /* out */ + BYTE **blob) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Delegate_CreateKeyDelegation_TP(entry, hKey, publicInfoSize, + publicInfo, encDelAuth, + keyAuth, blobSize, blob); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_Delegate_CreateOwnerDelegation(TSS_HCONTEXT hContext, /* in */ + TSS_BOOL increment, /* in */ + UINT32 publicInfoSize, /* in */ + BYTE *publicInfo, /* in */ + TPM_ENCAUTH *encDelAuth, /* in */ + TPM_AUTH *ownerAuth, /* in, out */ + UINT32 *blobSize, /* out */ + BYTE **blob) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Delegate_CreateOwnerDelegation_TP(entry, increment, + publicInfoSize, publicInfo, + encDelAuth, ownerAuth, + blobSize, blob); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_Delegate_LoadOwnerDelegation(TSS_HCONTEXT hContext, /* in */ + TPM_DELEGATE_INDEX index, /* in */ + UINT32 blobSize, /* in */ + BYTE *blob, /* in */ + TPM_AUTH *ownerAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Delegate_LoadOwnerDelegation_TP(entry, index, blobSize, blob, + ownerAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_Delegate_ReadTable(TSS_HCONTEXT hContext, /* in */ + UINT32 *familyTableSize, /* out */ + BYTE **familyTable, /* out */ + UINT32 *delegateTableSize, /* out */ + BYTE **delegateTable) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Delegate_ReadTable_TP(entry, familyTableSize, familyTable, + delegateTableSize, delegateTable); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_Delegate_UpdateVerificationCount(TSS_HCONTEXT hContext, /* in */ + UINT32 inputSize, /* in */ + BYTE *input, /* in */ + TPM_AUTH *ownerAuth, /* in, out */ + UINT32 *outputSize, /* out */ + BYTE **output) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Delegate_UpdateVerificationCount_TP(entry, inputSize, input, + ownerAuth, outputSize, + output); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_Delegate_VerifyDelegation(TSS_HCONTEXT hContext, /* in */ + UINT32 delegateSize, /* in */ + BYTE *delegate) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_Delegate_VerifyDelegation_TP(entry, delegateSize, delegate); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_DSAP(TSS_HCONTEXT hContext, /* in */ + TPM_ENTITY_TYPE entityType, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + TPM_NONCE *nonceOddDSAP, /* in */ + UINT32 entityValueSize, /* in */ + BYTE * entityValue, /* in */ + TCS_AUTHHANDLE *authHandle, /* out */ + TPM_NONCE *nonceEven, /* out */ + TPM_NONCE *nonceEvenDSAP) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_DSAP_TP(entry, entityType, keyHandle, nonceOddDSAP, + entityValueSize, entityValue, authHandle, nonceEven, + nonceEvenDSAP); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +#endif + +#ifdef TSS_BUILD_CMK +TSS_RESULT +RPC_CMK_SetRestrictions(TSS_HCONTEXT hContext, /* in */ + TSS_CMK_DELEGATE restriction, /* in */ + TPM_AUTH *ownerAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CMK_SetRestrictions_TP(entry, restriction, ownerAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_CMK_ApproveMA(TSS_HCONTEXT hContext, /* in */ + TPM_DIGEST migAuthorityDigest, /* in */ + TPM_AUTH *ownerAuth, /* in, out */ + TPM_HMAC *migAuthorityApproval) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CMK_ApproveMA_TP(entry, migAuthorityDigest, ownerAuth, + migAuthorityApproval); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_CMK_CreateKey(TSS_HCONTEXT hContext, /* in */ + TCS_KEY_HANDLE hWrappingKey, /* in */ + TPM_ENCAUTH *keyUsageAuth, /* in */ + TPM_HMAC *migAuthorityApproval, /* in */ + TPM_DIGEST *migAuthorityDigest, /* in */ + UINT32 *keyDataSize, /* in, out */ + BYTE **keyData, /* in, out */ + TPM_AUTH *pAuth) /* in, out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CMK_CreateKey_TP(entry, hWrappingKey, keyUsageAuth, + migAuthorityApproval, migAuthorityDigest, keyDataSize, + keyData, pAuth); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_CMK_CreateTicket(TSS_HCONTEXT hContext, /* in */ + UINT32 publicVerifyKeySize, /* in */ + BYTE *publicVerifyKey, /* in */ + TPM_DIGEST signedData, /* in */ + UINT32 sigValueSize, /* in */ + BYTE *sigValue, /* in */ + TPM_AUTH *ownerAuth, /* in, out */ + TPM_HMAC *sigTicket) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CMK_CreateTicket_TP(entry, publicVerifyKeySize, + publicVerifyKey, signedData, sigValueSize, sigValue, + ownerAuth, sigTicket); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_CMK_CreateBlob(TSS_HCONTEXT hContext, /* in */ + TCS_KEY_HANDLE hParentKey, /* in */ + TSS_MIGRATE_SCHEME migrationType, /* in */ + UINT32 migKeyAuthSize, /* in */ + BYTE *migKeyAuth, /* in */ + TPM_DIGEST pubSourceKeyDigest, /* in */ + UINT32 msaListSize, /* in */ + BYTE *msaList, /* in */ + UINT32 restrictTicketSize, /* in */ + BYTE *restrictTicket, /* in */ + UINT32 sigTicketSize, /* in */ + BYTE *sigTicket, /* in */ + UINT32 encDataSize, /* in */ + BYTE *encData, /* in */ + TPM_AUTH *pAuth, /* in, out */ + UINT32 *randomSize, /* out */ + BYTE **random, /* out */ + UINT32 *outDataSize, /* out */ + BYTE **outData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CMK_CreateBlob_TP(entry, hParentKey, migrationType, + migKeyAuthSize, migKeyAuth, pubSourceKeyDigest, + msaListSize, msaList, restrictTicketSize, restrictTicket, + sigTicketSize, sigTicket, encDataSize, encData, pAuth, + randomSize, random, outDataSize, outData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_CMK_ConvertMigration(TSS_HCONTEXT hContext, /* in */ + TCS_KEY_HANDLE hParentHandle, /* in */ + TPM_CMK_AUTH restrictTicket, /* in */ + TPM_HMAC sigTicket, /* in */ + UINT32 keyDataSize, /* in */ + BYTE *keyData, /* in */ + UINT32 msaListSize, /* in */ + BYTE *msaList, /* in */ + UINT32 randomSize, /* in */ + BYTE *random, /* in */ + TPM_AUTH *pAuth, /* in, out */ + UINT32 *outDataSize, /* out */ + BYTE **outData) /* out */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_CMK_ConvertMigration_TP(entry, hParentHandle, restrictTicket, + sigTicket, keyDataSize, keyData, msaListSize, msaList, + randomSize, random, pAuth, outDataSize, outData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + +#ifdef TSS_BUILD_TSS12 +TSS_RESULT +RPC_FlushSpecific(TSS_HCONTEXT hContext, /* in */ + TCS_HANDLE hResHandle, /* in */ + TPM_RESOURCE_TYPE resourceType) /* in */ +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_FlushSpecific_TP(entry, hResHandle, resourceType); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} + +TSS_RESULT +RPC_KeyControlOwner(TCS_CONTEXT_HANDLE hContext, /* in */ + TCS_KEY_HANDLE hKey, /* in */ + UINT32 ulPublicInfoLength, /* in */ + BYTE* rgbPublicInfo, /* in */ + UINT32 attribName, /* in */ + TSS_BOOL attribValue, /* in */ + TPM_AUTH* pOwnerAuth, /* in, out */ + TSS_UUID* pUuidData) /* out */ + +{ + TSS_RESULT result = (TSS_E_INTERNAL_ERROR | TSS_LAYER_TSP); + struct host_table_entry *entry = get_table_entry(hContext); + + if (entry == NULL) + return TSPERR(TSS_E_NO_CONNECTION); + + switch (entry->type) { + case CONNECTION_TYPE_TCP_PERSISTANT: + result = RPC_KeyControlOwner_TP(entry, hKey, + ulPublicInfoLength, + rgbPublicInfo, + attribName, + attribValue, + pOwnerAuth, + pUuidData); + break; + default: + break; + } + + put_table_entry(entry); + + return result; +} +#endif + diff --git a/src/tspi/rpc/tcstp/rpc.c b/src/tspi/rpc/tcstp/rpc.c new file mode 100644 index 0000000..da710f8 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc.c @@ -0,0 +1,514 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <unistd.h> +#include <errno.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> +#include <stdlib.h> +#include <stdio.h> +#include <assert.h> +#include <limits.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +void +initData(struct tcsd_comm_data *comm, int parm_count) +{ + /* min packet size should be the size of the header */ + memset(&comm->hdr, 0, sizeof(struct tcsd_packet_hdr)); + comm->hdr.packet_size = sizeof(struct tcsd_packet_hdr); + if (parm_count > 0) { + comm->hdr.type_offset = sizeof(struct tcsd_packet_hdr); + comm->hdr.parm_offset = comm->hdr.type_offset + + (sizeof(TCSD_PACKET_TYPE) * parm_count); + comm->hdr.packet_size = comm->hdr.parm_offset; + } + + memset(comm->buf, 0, comm->buf_size); +} + +int +loadData(UINT64 *offset, TCSD_PACKET_TYPE data_type, void *data, int data_size, BYTE *blob) +{ + switch (data_type) { + case TCSD_PACKET_TYPE_BYTE: + Trspi_LoadBlob_BYTE(offset, *((BYTE *) (data)), blob); + break; + case TCSD_PACKET_TYPE_BOOL: + Trspi_LoadBlob_BOOL(offset, *((TSS_BOOL *) (data)), blob); + break; + case TCSD_PACKET_TYPE_UINT16: + Trspi_LoadBlob_UINT16(offset, *((UINT16 *) (data)), blob); + break; + case TCSD_PACKET_TYPE_UINT32: + Trspi_LoadBlob_UINT32(offset, *((UINT32 *) (data)), blob); + break; + case TCSD_PACKET_TYPE_PBYTE: + Trspi_LoadBlob(offset, data_size, blob, (BYTE *)data); + break; + case TCSD_PACKET_TYPE_NONCE: + Trspi_LoadBlob(offset, 20, blob, ((TCPA_NONCE *)data)->nonce); + break; + case TCSD_PACKET_TYPE_DIGEST: + Trspi_LoadBlob(offset, 20, blob, ((TCPA_DIGEST *)data)->digest); + break; + case TCSD_PACKET_TYPE_AUTH: + LoadBlob_AUTH(offset, blob, ((TPM_AUTH *)data)); + break; + case TCSD_PACKET_TYPE_UUID: + Trspi_LoadBlob_UUID(offset, blob, *((TSS_UUID *)data)); + break; + case TCSD_PACKET_TYPE_ENCAUTH: + Trspi_LoadBlob(offset, 20, blob, ((TCPA_ENCAUTH *)data)->authdata); + break; + case TCSD_PACKET_TYPE_VERSION: + Trspi_LoadBlob_TCPA_VERSION(offset, blob, *((TCPA_VERSION *)data)); + break; +#ifdef TSS_BUILD_PS + case TCSD_PACKET_TYPE_LOADKEY_INFO: + LoadBlob_LOADKEY_INFO(offset, blob, ((TCS_LOADKEY_INFO *)data)); + break; +#endif + case TCSD_PACKET_TYPE_PCR_EVENT: + Trspi_LoadBlob_PCR_EVENT(offset, blob, ((TSS_PCR_EVENT *)data)); + break; + case TCSD_PACKET_TYPE_COUNTER_VALUE: + Trspi_LoadBlob_COUNTER_VALUE(offset, blob, ((TPM_COUNTER_VALUE *)data)); + break; + case TCSD_PACKET_TYPE_SECRET: + Trspi_LoadBlob(offset, 20, blob, ((TCPA_SECRET *)data)->authdata); + break; + default: + LogError("TCSD packet type unknown! (0x%x)", data_type & 0xff); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + return TSS_SUCCESS; +} + +int +setData(TCSD_PACKET_TYPE dataType, + int index, + void *theData, + int theDataSize, + struct tcsd_comm_data *comm) +{ + UINT64 old_offset, offset; + TSS_RESULT result; + TCSD_PACKET_TYPE *type; + + /* Calculate the size of the area needed (use NULL for blob address) */ + offset = 0; + if ((result = loadData(&offset, dataType, theData, theDataSize, NULL))) + return result; + if ((comm->hdr.packet_size + offset) > TSS_TPM_TXBLOB_SIZE) { + LogError("Too much data to be transmitted!"); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if ((comm->hdr.packet_size + offset) > comm->buf_size) { + /* reallocate the buffer */ + BYTE *buffer; + int buffer_size = comm->hdr.packet_size + offset; + + LogDebug("Increasing communication buffer to %d bytes.", buffer_size); + buffer = realloc(comm->buf, buffer_size); + if (buffer == NULL) { + LogError("realloc of %d bytes failed.", buffer_size); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + comm->buf_size = buffer_size; + comm->buf = buffer; + } + + offset = old_offset = comm->hdr.parm_offset + comm->hdr.parm_size; + if ((result = loadData(&offset, dataType, theData, theDataSize, comm->buf))) + return result; + type = (TCSD_PACKET_TYPE *)(comm->buf + comm->hdr.type_offset) + index; + *type = dataType; + comm->hdr.type_size += sizeof(TCSD_PACKET_TYPE); + comm->hdr.parm_size += (offset - old_offset); + + comm->hdr.packet_size = offset; + comm->hdr.num_parms++; + + return TSS_SUCCESS; +} + +UINT32 +getData(TCSD_PACKET_TYPE dataType, + int index, + void *theData, + int theDataSize, + struct tcsd_comm_data *comm) +{ + TSS_RESULT result; + UINT64 old_offset, offset; + TCSD_PACKET_TYPE *type = (TCSD_PACKET_TYPE *)(comm->buf + comm->hdr.type_offset) + index; + + if ((UINT32)index >= comm->hdr.num_parms || dataType != *type) { + LogDebug("Data type of TCS packet element %d doesn't match.", index); + return TSS_TCP_RPC_BAD_PACKET_TYPE; + } + old_offset = offset = comm->hdr.parm_offset; + switch (dataType) { + case TCSD_PACKET_TYPE_BYTE: + Trspi_UnloadBlob_BYTE(&offset, (BYTE *)theData, comm->buf); + break; + case TCSD_PACKET_TYPE_BOOL: + Trspi_UnloadBlob_BOOL(&offset, (TSS_BOOL *)theData, comm->buf); + break; + case TCSD_PACKET_TYPE_UINT16: + Trspi_UnloadBlob_UINT16(&offset, (UINT16 *)theData, comm->buf); + break; + case TCSD_PACKET_TYPE_UINT32: + Trspi_UnloadBlob_UINT32(&offset, (UINT32 *)theData, comm->buf); + break; + case TCSD_PACKET_TYPE_UINT64: + Trspi_UnloadBlob_UINT64(&offset, (UINT64 *)theData, comm->buf); + break; + case TCSD_PACKET_TYPE_PBYTE: + Trspi_UnloadBlob(&offset, theDataSize, comm->buf, (BYTE *)theData); + break; + case TCSD_PACKET_TYPE_NONCE: + Trspi_UnloadBlob_NONCE(&offset, comm->buf, (TPM_NONCE *)theData); + break; + case TCSD_PACKET_TYPE_DIGEST: + Trspi_UnloadBlob(&offset, sizeof(TCPA_DIGEST), comm->buf, + ((TCPA_DIGEST *)theData)->digest); + break; + case TCSD_PACKET_TYPE_AUTH: + UnloadBlob_AUTH(&offset, comm->buf, ((TPM_AUTH *)theData)); + break; + case TCSD_PACKET_TYPE_UUID: + Trspi_UnloadBlob_UUID(&offset, comm->buf, ((TSS_UUID *)theData)); + break; + case TCSD_PACKET_TYPE_ENCAUTH: + Trspi_UnloadBlob(&offset, sizeof(TCPA_ENCAUTH), comm->buf, + ((TCPA_ENCAUTH *)theData)->authdata); + break; + case TCSD_PACKET_TYPE_VERSION: + Trspi_UnloadBlob_TCPA_VERSION(&offset, comm->buf, + ((TCPA_VERSION *)theData)); + break; + case TCSD_PACKET_TYPE_KM_KEYINFO: + if ((result = Trspi_UnloadBlob_KM_KEYINFO(&offset, comm->buf, + ((TSS_KM_KEYINFO *)theData)))) + return result; + break; + case TCSD_PACKET_TYPE_KM_KEYINFO2: + if ((result = Trspi_UnloadBlob_KM_KEYINFO2(&offset, comm->buf, + ((TSS_KM_KEYINFO2 *)theData)))) + return result; + break; +#ifdef TSS_BUILD_PS + case TCSD_PACKET_TYPE_LOADKEY_INFO: + UnloadBlob_LOADKEY_INFO(&offset, comm->buf, ((TCS_LOADKEY_INFO *)theData)); + break; +#endif + case TCSD_PACKET_TYPE_PCR_EVENT: + if ((result = Trspi_UnloadBlob_PCR_EVENT(&offset, comm->buf, + ((TSS_PCR_EVENT *)theData)))) + return result; + break; + case TCSD_PACKET_TYPE_COUNTER_VALUE: + Trspi_UnloadBlob_COUNTER_VALUE(&offset, comm->buf, + ((TPM_COUNTER_VALUE *)theData)); + break; + case TCSD_PACKET_TYPE_SECRET: + Trspi_UnloadBlob(&offset, sizeof(TCPA_SECRET), comm->buf, + ((TCPA_SECRET *)theData)->authdata); + break; + default: + LogError("unknown data type (%d) in TCSD packet!", dataType); + return -1; + } + comm->hdr.parm_offset = offset; + comm->hdr.parm_size -= (offset - old_offset); + + return TSS_SUCCESS; +} + +TSS_RESULT +sendTCSDPacket(struct host_table_entry *hte) +{ + TSS_RESULT rc; + UINT64 offset = 0; + + Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.packet_size, hte->comm.buf); + Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.u.ordinal, hte->comm.buf); + Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.num_parms, hte->comm.buf); + Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.type_size, hte->comm.buf); + Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.type_offset, hte->comm.buf); + Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.parm_size, hte->comm.buf); + Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.parm_offset, hte->comm.buf); + +#if 0 + /* --- Send it */ + printBuffer(hte->comm.buf, hte->comm.hdr.packet_size); + LogInfo("Sending Packet with TCSD ordinal 0x%X", hte->comm.hdr.u.ordinal); +#endif + /* if the ordinal is open context, there are some host table entry + * manipulations that must be done, so call _init + */ + if (hte->comm.hdr.u.ordinal == TCSD_ORD_OPENCONTEXT) { + if ((rc = send_init(hte))) { + LogError("Failed to send packet"); + return rc; + } + } else { + if ((rc = tcs_sendit(hte))) { + LogError("Failed to send packet"); + return rc; + } + } + + /* create a platform version of the tcsd header */ + offset = 0; + Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.packet_size, hte->comm.buf); + Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.u.result, hte->comm.buf); + Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.num_parms, hte->comm.buf); + Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.type_size, hte->comm.buf); + Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.type_offset, hte->comm.buf); + Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.parm_size, hte->comm.buf); + Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.parm_offset, hte->comm.buf); + + return TSS_SUCCESS; +} + +int +recv_from_socket(int sock, void *buffer, int size) +{ + int recv_size = 0, recv_total = 0; + + while (recv_total < size) { + errno = 0; + if ((recv_size = recv(sock, buffer+recv_total, size-recv_total, 0)) <= 0) { + if (recv_size < 0) { + if (errno == EINTR) + continue; + LogError("Socket receive connection error: %s.", strerror(errno)); + } else { + LogDebug("Socket connection closed."); + } + + return -1; + } + recv_total += recv_size; + } + + return recv_total; +} + +int +send_to_socket(int sock, void *buffer, int size) +{ + int send_size = 0, send_total = 0; + + while (send_total < size) { + if ((send_size = send(sock, buffer+send_total, size-send_total, 0)) < 0) { + LogError("Socket send connection error: %s.", strerror(errno)); + return -1; + } + send_total += send_size; + } + + return send_total; +} + +TSS_RESULT +send_init(struct host_table_entry *hte) +{ + int sd; + int recv_size; + BYTE *buffer; + TSS_RESULT result; + + struct sockaddr_in addr; + struct hostent *hEnt = NULL; + + sd = socket(PF_INET, SOCK_STREAM, 0); + if (sd == -1) { + LogError("socket: %s", strerror(errno)); + result = TSPERR(TSS_E_COMM_FAILURE); + goto err_exit; + } + + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_port = htons(get_port()); + + LogDebug("Sending TSP packet to host %s.", hte->hostname); + + /* try to resolve by hostname first */ + hEnt = gethostbyname((char *)hte->hostname); + if (hEnt == NULL) { + /* if by hostname fails, try by dot notation */ + if (inet_aton((char *)hte->hostname, &addr.sin_addr) == 0) { + LogError("hostname %s does not resolve to a valid address.", hte->hostname); + result = TSPERR(TSS_E_CONNECTION_FAILED); + goto err_exit; + } + } else { + memcpy(&addr.sin_addr, hEnt->h_addr_list[0], 4); + } + + LogDebug("Connecting to %s", inet_ntoa(addr.sin_addr)); + + if (connect(sd, (struct sockaddr *) &addr, sizeof (addr))) { + LogError("connect: %s", strerror(errno)); + result = TSPERR(TSS_E_COMM_FAILURE); + goto err_exit; + } + + if (send_to_socket(sd, hte->comm.buf, hte->comm.hdr.packet_size) < 0) { + result = TSPERR(TSS_E_COMM_FAILURE); + goto err_exit; + } + + buffer = hte->comm.buf; + recv_size = sizeof(struct tcsd_packet_hdr); + if (recv_from_socket(sd, buffer, recv_size) < 0) { + result = TSPERR(TSS_E_COMM_FAILURE); + goto err_exit; + } + buffer += sizeof(struct tcsd_packet_hdr); /* increment the receive buffer pointer */ + + /* check the packet size */ + recv_size = Decode_UINT32(hte->comm.buf); + if (recv_size < (int)sizeof(struct tcsd_packet_hdr)) { + LogError("Packet to receive from socket %d is too small (%d bytes)", + sd, recv_size); + result = TSPERR(TSS_E_COMM_FAILURE); + goto err_exit; + } + + if (recv_size > (int) hte->comm.buf_size ) { + BYTE *new_buffer; + + LogDebug("Increasing communication buffer to %d bytes.", recv_size); + new_buffer = realloc(hte->comm.buf, recv_size); + if (new_buffer == NULL) { + LogError("realloc of %d bytes failed.", recv_size); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto err_exit; + } + buffer = new_buffer + sizeof(struct tcsd_packet_hdr); + hte->comm.buf_size = recv_size; + hte->comm.buf = new_buffer; + } + + /* get the rest of the packet */ + recv_size -= sizeof(struct tcsd_packet_hdr); /* already received the header */ + if (recv_from_socket(sd, buffer, recv_size) < 0) { + result = TSPERR(TSS_E_COMM_FAILURE); + goto err_exit; + } + + hte->socket = sd; + + return TSS_SUCCESS; + +err_exit: + close(sd); + return result; +} + +TSS_RESULT +tcs_sendit(struct host_table_entry *hte) +{ + int recv_size; + BYTE *buffer; + TSS_RESULT result; + + if (send_to_socket(hte->socket, hte->comm.buf, hte->comm.hdr.packet_size) < 0) { + result = TSPERR(TSS_E_COMM_FAILURE); + goto err_exit; + } + + buffer = hte->comm.buf; + recv_size = sizeof(struct tcsd_packet_hdr); + if ((recv_size = recv_from_socket(hte->socket, buffer, recv_size)) < 0) { + result = TSPERR(TSS_E_COMM_FAILURE); + goto err_exit; + } + buffer += recv_size; /* increment the receive buffer pointer */ + + /* check the packet size */ + recv_size = Decode_UINT32(hte->comm.buf); + if (recv_size < (int)sizeof(struct tcsd_packet_hdr)) { + LogError("Packet to receive from socket %d is too small (%d bytes)", + hte->socket, recv_size); + result = TSPERR(TSS_E_COMM_FAILURE); + goto err_exit; + } + + if (recv_size > (int) hte->comm.buf_size ) { + BYTE *new_buffer; + + LogDebug("Increasing communication buffer to %d bytes.", recv_size); + new_buffer = realloc(hte->comm.buf, recv_size); + if (new_buffer == NULL) { + LogError("realloc of %d bytes failed.", recv_size); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto err_exit; + } + buffer = new_buffer + sizeof(struct tcsd_packet_hdr); + hte->comm.buf_size = recv_size; + hte->comm.buf = new_buffer; + } + + /* get the rest of the packet */ + recv_size -= sizeof(struct tcsd_packet_hdr); /* already received the header */ + if ((recv_size = recv_from_socket(hte->socket, buffer, recv_size)) < 0) { + result = TSPERR(TSS_E_COMM_FAILURE); + goto err_exit; + } + + return TSS_SUCCESS; + +err_exit: + return result; +} + +/* XXX this should be moved out of an RPC-specific file */ +short +get_port(void) +{ + char *env_port; + int port = 0; + + env_port = getenv("TSS_TCSD_PORT"); + + if (env_port == NULL) + return TCSD_DEFAULT_PORT; + + port = atoi(env_port); + + if (port == 0 || port > 65535) + return TCSD_DEFAULT_PORT; + + return (short)port; +} + diff --git a/src/tspi/rpc/tcstp/rpc_admin.c b/src/tspi/rpc/tcstp/rpc_admin.c new file mode 100644 index 0000000..e29726e --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_admin.c @@ -0,0 +1,373 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2007 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_SetOwnerInstall_TP(struct host_table_entry *hte, + TSS_BOOL state) /* in */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_SETOWNERINSTALL; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_BOOL, 1, &state, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_DisableOwnerClear_TP(struct host_table_entry *hte, + TPM_AUTH * ownerAuth) /* in, out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_DISABLEOWNERCLEAR; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (setData(TCSD_PACKET_TYPE_AUTH, 1, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS ){ + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_ForceClear_TP(struct host_table_entry *hte) +{ + TSS_RESULT result; + + initData(&hte->comm, 1); + hte->comm.hdr.u.ordinal = TCSD_ORD_FORCECLEAR; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_DisableForceClear_TP(struct host_table_entry *hte) +{ + TSS_RESULT result; + + initData(&hte->comm, 1); + hte->comm.hdr.u.ordinal = TCSD_ORD_DISABLEFORCECLEAR; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_PhysicalDisable_TP(struct host_table_entry *hte) +{ + TSS_RESULT result; + + initData(&hte->comm, 1); + hte->comm.hdr.u.ordinal = TCSD_ORD_PHYSICALDISABLE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_PhysicalEnable_TP(struct host_table_entry *hte) +{ + TSS_RESULT result; + + initData(&hte->comm, 1); + hte->comm.hdr.u.ordinal = TCSD_ORD_PHYSICALENABLE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_OwnerSetDisable_TP(struct host_table_entry *hte, + TSS_BOOL disableState, /* in */ + TPM_AUTH * ownerAuth) /* in, out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_OWNERSETDISABLE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_BOOL, 1, &disableState, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 2, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_PhysicalSetDeactivated_TP(struct host_table_entry *hte, + TSS_BOOL state) /* in */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_PHYSICALSETDEACTIVATED; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_BOOL, 1, &state, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_PhysicalPresence_TP(struct host_table_entry *hte, + TCPA_PHYSICAL_PRESENCE fPhysicalPresence) /* in */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_PHYSICALPRESENCE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT16, 1, &fPhysicalPresence, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_SetTempDeactivated_TP(struct host_table_entry *hte) +{ + TSS_RESULT result; + + initData(&hte->comm, 1); + hte->comm.hdr.u.ordinal = TCSD_ORD_SETTEMPDEACTIVATED; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +#ifdef TSS_BUILD_TSS12 +TSS_RESULT +RPC_SetTempDeactivated2_TP(struct host_table_entry *hte, + TPM_AUTH *operatorAuth) /* in/out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_SETTEMPDEACTIVATED2; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (operatorAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 1, operatorAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + TPM_AUTH nullAuth; + + memset(&nullAuth, 0, sizeof(TPM_AUTH)); + if (setData(TCSD_PACKET_TYPE_AUTH, 1, &nullAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (operatorAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, operatorAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + + return result; +} +#endif + +TSS_RESULT +RPC_FieldUpgrade_TP(struct host_table_entry *hte, + UINT32 dataInSize, /* in */ + BYTE * dataIn, /* in */ + UINT32 * dataOutSize, /* out */ + BYTE ** dataOut, /* out */ + TPM_AUTH * ownerAuth) /* in, out */ +{ + return TSPERR(TSS_E_NOTIMPL); +} + +TSS_RESULT +RPC_SetRedirection_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE keyHandle, /* in */ + UINT32 c1, /* in */ + UINT32 c2, /* in */ + TPM_AUTH * privAuth) /* in, out */ +{ + return TSPERR(TSS_E_NOTIMPL); + +} + +#ifdef TSS_BUILD_TSS12 +TSS_RESULT +RPC_ResetLockValue_TP(struct host_table_entry *hte, + TPM_AUTH * ownerAuth) /* in, out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_RESETLOCKVALUE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 1, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_FlushSpecific_TP(struct host_table_entry *hte, + TCS_HANDLE hResHandle, /* in */ + TPM_RESOURCE_TYPE resourceType) /* in */ +{ + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_FLUSHSPECIFIC; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hResHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &resourceType, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} +#endif diff --git a/src/tspi/rpc/tcstp/rpc_aik.c b/src/tspi/rpc/tcstp/rpc_aik.c new file mode 100644 index 0000000..cd40845 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_aik.c @@ -0,0 +1,336 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2007 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_MakeIdentity_TP(struct host_table_entry *hte, + TCPA_ENCAUTH identityAuth, /* in */ + TCPA_CHOSENID_HASH IDLabel_PrivCAHash, /* in */ + UINT32 idKeyInfoSize, /* in */ + BYTE * idKeyInfo, /* in */ + TPM_AUTH * pSrkAuth, /* in, out */ + TPM_AUTH * pOwnerAuth, /* in, out */ + UINT32 * idKeySize, /* out */ + BYTE ** idKey, /* out */ + UINT32 * pcIdentityBindingSize, /* out */ + BYTE ** prgbIdentityBinding, /* out */ + UINT32 * pcEndorsementCredentialSize, /* out */ + BYTE ** prgbEndorsementCredential, /* out */ + UINT32 * pcPlatformCredentialSize, /* out */ + BYTE ** prgbPlatformCredential, /* out */ + UINT32 * pcConformanceCredentialSize, /* out */ + BYTE ** prgbConformanceCredential) /* out */ +{ + TSS_RESULT result; + int i; + + initData(&hte->comm, 7); + hte->comm.hdr.u.ordinal = TCSD_ORD_MAKEIDENTITY; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_ENCAUTH, 1, &identityAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_DIGEST, 2, &IDLabel_PrivCAHash, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 3, &idKeyInfoSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 4, idKeyInfo, idKeyInfoSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + i = 5; + if (pSrkAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, i++, pSrkAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (setData(TCSD_PACKET_TYPE_AUTH, i++, pOwnerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + i = 0; + if (result == TSS_SUCCESS) { + i = 0; + if (pSrkAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, pSrkAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_AUTH, i++, pOwnerAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, idKeySize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *idKey = (BYTE *) malloc(*idKeySize); + if (*idKey == NULL) { + LogError("malloc of %u bytes failed.", *idKeySize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *idKey, *idKeySize, &hte->comm)) { + free(*idKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcIdentityBindingSize, 0, &hte->comm)) { + free(*idKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *prgbIdentityBinding = (BYTE *) malloc(*pcIdentityBindingSize); + if (*prgbIdentityBinding == NULL) { + LogError("malloc of %u bytes failed.", *pcIdentityBindingSize); + free(*idKey); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbIdentityBinding, *pcIdentityBindingSize, &hte->comm)) { + free(*idKey); + free(*prgbIdentityBinding); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcEndorsementCredentialSize, 0, &hte->comm)) { + free(*idKey); + free(*prgbIdentityBinding); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *prgbEndorsementCredential = (BYTE *) malloc(*pcEndorsementCredentialSize); + if (*prgbEndorsementCredential == NULL) { + LogError("malloc of %u bytes failed.", *pcEndorsementCredentialSize); + free(*idKey); + free(*prgbIdentityBinding); + *prgbIdentityBinding = NULL; + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbEndorsementCredential, *pcEndorsementCredentialSize, &hte->comm)) { + free(*idKey); + free(*prgbIdentityBinding); + *prgbIdentityBinding = NULL; + free(*prgbEndorsementCredential); + *prgbEndorsementCredential = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcPlatformCredentialSize, 0, &hte->comm)) { + free(*idKey); + free(*prgbIdentityBinding); + *prgbIdentityBinding = NULL; + free(*prgbEndorsementCredential); + *prgbEndorsementCredential = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *prgbPlatformCredential = (BYTE *) malloc(*pcPlatformCredentialSize); + if (*prgbPlatformCredential == NULL) { + LogError("malloc of %u bytes failed.", *pcPlatformCredentialSize); + free(*idKey); + free(*prgbIdentityBinding); + *prgbIdentityBinding = NULL; + free(*prgbEndorsementCredential); + *prgbEndorsementCredential = NULL; + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbPlatformCredential, *pcPlatformCredentialSize, &hte->comm)) { + free(*idKey); + free(*prgbIdentityBinding); + *prgbIdentityBinding = NULL; + free(*prgbEndorsementCredential); + *prgbEndorsementCredential = NULL; + free(*prgbPlatformCredential); + *prgbPlatformCredential = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcConformanceCredentialSize, 0, &hte->comm)) { + free(*idKey); + free(*prgbIdentityBinding); + *prgbIdentityBinding = NULL; + free(*prgbEndorsementCredential); + *prgbEndorsementCredential = NULL; + free(*prgbPlatformCredential); + *prgbPlatformCredential = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *prgbConformanceCredential = (BYTE *) malloc(*pcConformanceCredentialSize); + if (*prgbConformanceCredential == NULL) { + LogError("malloc of %u bytes failed.", *pcConformanceCredentialSize); + free(*idKey); + free(*prgbIdentityBinding); + *prgbIdentityBinding = NULL; + free(*prgbEndorsementCredential); + *prgbEndorsementCredential = NULL; + free(*prgbPlatformCredential); + *prgbPlatformCredential = NULL; + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbConformanceCredential, *pcConformanceCredentialSize, &hte->comm)) { + free(*idKey); + free(*prgbIdentityBinding); + *prgbIdentityBinding = NULL; + free(*prgbEndorsementCredential); + *prgbEndorsementCredential = NULL; + free(*prgbPlatformCredential); + *prgbPlatformCredential = NULL; + free(*prgbConformanceCredential); + *prgbConformanceCredential = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} + +TSS_RESULT +RPC_GetCredential_TP(struct host_table_entry *hte, + UINT32 ulCredentialType, /* in */ + UINT32 ulCredentialAccessMode, /* in */ + UINT32 * pulCredentialSize, /* out */ + BYTE ** prgbCredentialData) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_GETCREDENTIAL; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &ulCredentialType, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &ulCredentialAccessMode, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, pulCredentialSize, 0, &hte->comm)) { + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + *prgbCredentialData = (BYTE *) malloc(*pulCredentialSize); + if (*prgbCredentialData == NULL) { + LogError("malloc of %u bytes failed.", *pulCredentialSize); + return TSPERR(TSS_E_OUTOFMEMORY); + } + + if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *prgbCredentialData, + *pulCredentialSize, &hte->comm)) { + free(*prgbCredentialData); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + return result; +} + +TSS_RESULT +RPC_ActivateTPMIdentity_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE idKey, /* in */ + UINT32 blobSize, /* in */ + BYTE * blob, /* in */ + TPM_AUTH * idKeyAuth, /* in, out */ + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * SymmetricKeySize, /* out */ + BYTE ** SymmetricKey) /* out */ +{ + TSS_RESULT result; + int i = 0; + + initData(&hte->comm, 6); + hte->comm.hdr.u.ordinal = TCSD_ORD_ACTIVATETPMIDENTITY; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &idKey, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &blobSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, i++, blob, blobSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (idKeyAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, i++, idKeyAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (setData(TCSD_PACKET_TYPE_AUTH, i++, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (idKeyAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, idKeyAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_AUTH, i++, ownerAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, SymmetricKeySize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *SymmetricKey = malloc(*SymmetricKeySize); + if (*SymmetricKey == NULL) { + LogError("malloc of %u bytes failed.", *SymmetricKeySize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *SymmetricKey, *SymmetricKeySize, &hte->comm)) { + free(*SymmetricKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } +done: + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_audit.c b/src/tspi/rpc/tcstp/rpc_audit.c new file mode 100644 index 0000000..63cc0e2 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_audit.c @@ -0,0 +1,240 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2007 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_SetOrdinalAuditStatus_TP(struct host_table_entry *hte, + TPM_AUTH *ownerAuth, /* in/out */ + UINT32 ulOrdinal, /* in */ + TSS_BOOL bAuditState) /* in */ +{ + TSS_RESULT result; + + initData(&hte->comm, 4); + hte->comm.hdr.u.ordinal = TCSD_ORD_SETORDINALAUDITSTATUS; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &ulOrdinal, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_BOOL, 2, &bAuditState, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 3, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_GetAuditDigest_TP(struct host_table_entry *hte, + UINT32 startOrdinal, /* in */ + TPM_DIGEST *auditDigest, /* out */ + UINT32 *counterValueSize, /* out */ + BYTE **counterValue, /* out */ + TSS_BOOL *more, /* out */ + UINT32 *ordSize, /* out */ + UINT32 **ordList) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_GETAUDITDIGEST; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &startOrdinal, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_DIGEST, 0, auditDigest, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, 1, counterValueSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *counterValue = (BYTE *)malloc(*counterValueSize); + if (*counterValue == NULL) { + LogError("malloc of %u bytes failed.", *counterValueSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *counterValue, *counterValueSize, &hte->comm)) { + free(*counterValue); + *counterValue = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_BOOL, 3, more, 0, &hte->comm)) { + free(*counterValue); + *counterValue = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, 4, ordSize, 0, &hte->comm)) { + free(*counterValue); + *counterValue = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *ordList = (UINT32 *)malloc(*ordSize * sizeof(UINT32)); + if (*ordList == NULL) { + LogError("malloc of %u bytes failed.", *ordSize); + free(*counterValue); + *counterValue = NULL; + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 5, *ordList, *ordSize * sizeof(UINT32), &hte->comm)) { + free(*counterValue); + *counterValue = NULL; + free(*ordList); + *ordList = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + +done: + return result; +} + +TSS_RESULT +RPC_GetAuditDigestSigned_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE keyHandle, /* in */ + TSS_BOOL closeAudit, /* in */ + TPM_NONCE *antiReplay, /* in */ + TPM_AUTH *privAuth, /* in/out */ + UINT32 *counterValueSize, /* out */ + BYTE **counterValue, /* out */ + TPM_DIGEST *auditDigest, /* out */ + TPM_DIGEST *ordinalDigest, /* out */ + UINT32 *sigSize, /* out */ + BYTE **sig) /* out */ +{ + TSS_RESULT result; + TPM_AUTH null_auth; + int i; + + initData(&hte->comm, 5); + hte->comm.hdr.u.ordinal = TCSD_ORD_GETAUDITDIGESTSIGNED; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + memset(&null_auth, 0, sizeof(TPM_AUTH)); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_BOOL, 2, &closeAudit, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 3, antiReplay, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (privAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 4, privAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + else { + if (setData(TCSD_PACKET_TYPE_AUTH, 4, &null_auth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (privAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, counterValueSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *counterValue = (BYTE *)malloc(*counterValueSize); + if (*counterValue == NULL) { + LogError("malloc of %u bytes failed.", *counterValueSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *counterValue, *counterValueSize, &hte->comm)) { + free(*counterValue); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_DIGEST, i++, auditDigest, 0, &hte->comm)) { + free(*counterValue); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_DIGEST, i++, ordinalDigest, 0, &hte->comm)) { + free(*counterValue); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, sigSize, 0, &hte->comm)) { + free(*counterValue); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *sig = (BYTE *)malloc(*sigSize); + if (*sig == NULL) { + LogError("malloc of %u bytes failed.", *sigSize); + free(*counterValue); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *sig, *sigSize, &hte->comm)) { + free(*counterValue); + free(*sig); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + +done: + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_auth.c b/src/tspi/rpc/tcstp/rpc_auth.c new file mode 100644 index 0000000..266d485 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_auth.c @@ -0,0 +1,96 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_OIAP_TP(struct host_table_entry *hte, + TCS_AUTHHANDLE * authHandle, /* out */ + TCPA_NONCE * nonce0 /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 1); + hte->comm.hdr.u.ordinal = TCSD_ORD_OIAP; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, authHandle, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_NONCE, 1, nonce0, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_OSAP_TP(struct host_table_entry *hte, + TCPA_ENTITY_TYPE entityType, /* in */ + UINT32 entityValue, /* in */ + TCPA_NONCE * nonceOddOSAP, /* in */ + TCS_AUTHHANDLE * authHandle, /* out */ + TCPA_NONCE * nonceEven, /* out */ + TCPA_NONCE * nonceEvenOSAP /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 4); + hte->comm.hdr.u.ordinal = TCSD_ORD_OSAP; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT16, 1, &entityType, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &entityValue, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 3, nonceOddOSAP, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, authHandle, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_NONCE, 1, nonceEven, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_NONCE, 2, nonceEvenOSAP, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_bind.c b/src/tspi/rpc/tcstp/rpc_bind.c new file mode 100644 index 0000000..79d7588 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_bind.c @@ -0,0 +1,90 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_UnBind_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE keyHandle, /* in */ + UINT32 inDataSize, /* in */ + BYTE * inData, /* in */ + TPM_AUTH * privAuth, /* in, out */ + UINT32 * outDataSize, /* out */ + BYTE ** outData /* out */ + ) { + TSS_RESULT result; + int i; + + initData(&hte->comm, 5); + hte->comm.hdr.u.ordinal = TCSD_ORD_UNBIND; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &inDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, inData, inDataSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (privAuth != NULL) { + if (setData(TCSD_PACKET_TYPE_AUTH, 4, privAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (privAuth != NULL) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, outDataSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *outData = (BYTE *) malloc(*outDataSize); + if (*outData == NULL) { + LogError("malloc of %u bytes failed.", *outDataSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outData, *outDataSize, &hte->comm)) { + free(*outData); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_caps.c b/src/tspi/rpc/tcstp/rpc_caps.c new file mode 100644 index 0000000..b626c55 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_caps.c @@ -0,0 +1,76 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_GetCapability_TP(struct host_table_entry *hte, + TCPA_CAPABILITY_AREA capArea, /* in */ + UINT32 subCapSize, /* in */ + BYTE * subCap, /* in */ + UINT32 * respSize, /* out */ + BYTE ** resp) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 4); + hte->comm.hdr.u.ordinal = TCSD_ORD_TCSGETCAPABILITY; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &capArea, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &subCapSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, subCap, subCapSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, respSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *resp = (BYTE *) calloc_tspi(hte->tspContext, *respSize); + if (*resp == NULL) { + LogError("malloc of %u bytes failed.", *respSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *resp, *respSize, &hte->comm)) { + free_tspi(hte->tspContext, *resp); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_caps_tpm.c b/src/tspi/rpc/tcstp/rpc_caps_tpm.c new file mode 100644 index 0000000..8957529 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_caps_tpm.c @@ -0,0 +1,175 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_GetTPMCapability_TP(struct host_table_entry *hte, + TCPA_CAPABILITY_AREA capArea, /* in */ + UINT32 subCapSize, /* in */ + BYTE * subCap, /* in */ + UINT32 * respSize, /* out */ + BYTE ** resp) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 4); + hte->comm.hdr.u.ordinal = TCSD_ORD_GETCAPABILITY; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &capArea, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &subCapSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, subCap, subCapSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, respSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *resp = (BYTE *) malloc(*respSize); + if (*resp == NULL) { + LogError("malloc of %u bytes failed.", *respSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *resp, *respSize, &hte->comm)) { + free(*resp); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} + +TSS_RESULT +RPC_GetCapabilitySigned_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE keyHandle, /* in */ + TCPA_NONCE antiReplay, /* in */ + TCPA_CAPABILITY_AREA capArea, /* in */ + UINT32 subCapSize, /* in */ + BYTE * subCap, /* in */ + TPM_AUTH * privAuth, /* in, out */ + TCPA_VERSION * Version, /* out */ + UINT32 * respSize, /* out */ + BYTE ** resp, /* out */ + UINT32 * sigSize, /* out */ + BYTE ** sig) /* out */ +{ + return TSPERR(TSS_E_NOTIMPL); +} + +TSS_RESULT +RPC_GetCapabilityOwner_TP(struct host_table_entry *hte, + TPM_AUTH * pOwnerAuth, /* out */ + TCPA_VERSION * pVersion, /* out */ + UINT32 * pNonVolatileFlags, /* out */ + UINT32 * pVolatileFlags) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_GETCAPABILITYOWNER; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 1, pOwnerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_VERSION, 0, pVersion, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_UINT32, 1, pNonVolatileFlags, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_UINT32, 2, pVolatileFlags, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_AUTH, 3, pOwnerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_SetCapability_TP(struct host_table_entry *hte, + TCPA_CAPABILITY_AREA capArea, /* in */ + UINT32 subCapSize, /* in */ + BYTE * subCap, /* in */ + UINT32 valueSize, /* in */ + BYTE * value, /* in */ + TPM_AUTH * pOwnerAuth) /* in, out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 7); + hte->comm.hdr.u.ordinal = TCSD_ORD_SETCAPABILITY; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &capArea, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &subCapSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, subCap, subCapSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 4, &valueSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 5, value, valueSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (pOwnerAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 6, pOwnerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, pOwnerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_certify.c b/src/tspi/rpc/tcstp/rpc_certify.c new file mode 100644 index 0000000..3568c94 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_certify.c @@ -0,0 +1,131 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_CertifyKey_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE certHandle, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + TPM_NONCE * antiReplay, /* in */ + TPM_AUTH * certAuth, /* in, out */ + TPM_AUTH * keyAuth, /* in, out */ + UINT32 * CertifyInfoSize, /* out */ + BYTE ** CertifyInfo, /* out */ + UINT32 * outDataSize, /* out */ + BYTE ** outData /* out */ + ) { + TSS_RESULT result; + TPM_AUTH null_auth; + int i; + + initData(&hte->comm, 6); + memset(&null_auth, 0, sizeof(TPM_AUTH)); + + hte->comm.hdr.u.ordinal = TCSD_ORD_CERTIFYKEY; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &certHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &keyHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 3, antiReplay, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (certAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 4, certAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + if (setData(TCSD_PACKET_TYPE_AUTH, 4, &null_auth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (keyAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 5, keyAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + if (setData(TCSD_PACKET_TYPE_AUTH, 5, &null_auth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (certAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, certAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (keyAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, keyAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, CertifyInfoSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *CertifyInfo = (BYTE *) malloc(*CertifyInfoSize); + if (*CertifyInfo == NULL) { + LogError("malloc of %u bytes failed.", *CertifyInfoSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *CertifyInfo, *CertifyInfoSize, &hte->comm)) { + free(*CertifyInfo); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, outDataSize, 0, &hte->comm)) { + free(*CertifyInfo); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *outData = (BYTE *) malloc(*outDataSize); + if (*outData == NULL) { + LogError("malloc of %u bytes failed.", *outDataSize); + free(*CertifyInfo); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outData, *outDataSize, &hte->comm)) { + free(*CertifyInfo); + free(*outData); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + +done: + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_changeauth.c b/src/tspi/rpc/tcstp/rpc_changeauth.c new file mode 100644 index 0000000..b4c3d87 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_changeauth.c @@ -0,0 +1,173 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_ChangeAuth_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE parentHandle, /* in */ + TCPA_PROTOCOL_ID protocolID, /* in */ + TCPA_ENCAUTH *newAuth, /* in */ + TCPA_ENTITY_TYPE entityType, /* in */ + UINT32 encDataSize, /* in */ + BYTE * encData, /* in */ + TPM_AUTH * ownerAuth, /* in, out */ + TPM_AUTH * entityAuth, /* in, out */ + UINT32 * outDataSize, /* out */ + BYTE ** outData) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 9); + hte->comm.hdr.u.ordinal = TCSD_ORD_CHANGEAUTH; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &parentHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT16, 2, &protocolID, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_ENCAUTH, 3, newAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT16, 4, &entityType, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 5, &encDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 6, encData, encDataSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 7, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 8, entityAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_AUTH, 1, entityAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, 2, outDataSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *outData = (BYTE *) malloc(*outDataSize); + if (*outData == NULL) { + LogError("malloc of %u bytes failed.", *outDataSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 3, *outData, *outDataSize, &hte->comm)) { + free(*outData); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} + +TSS_RESULT +RPC_ChangeAuthOwner_TP(struct host_table_entry *hte, + TCPA_PROTOCOL_ID protocolID, /* in */ + TCPA_ENCAUTH *newAuth, /* in */ + TCPA_ENTITY_TYPE entityType, /* in */ + TPM_AUTH * ownerAuth /* in, out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 5); + hte->comm.hdr.u.ordinal = TCSD_ORD_CHANGEAUTHOWNER; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT16, 1, &protocolID, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_ENCAUTH, 2, newAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT16, 3, &entityType, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 4, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (hte->comm.hdr.u.result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_ChangeAuthAsymStart_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE idHandle, /* in */ + TCPA_NONCE antiReplay, /* in */ + UINT32 KeySizeIn, /* in */ + BYTE * KeyDataIn, /* in */ + TPM_AUTH * pAuth, /* in, out */ + UINT32 * KeySizeOut, /* out */ + BYTE ** KeyDataOut, /* out */ + UINT32 * CertifyInfoSize, /* out */ + BYTE ** CertifyInfo, /* out */ + UINT32 * sigSize, /* out */ + BYTE ** sig, /* out */ + TCS_KEY_HANDLE * ephHandle /* out */ + ) { + return TSPERR(TSS_E_NOTIMPL); +} + +TSS_RESULT +RPC_ChangeAuthAsymFinish_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE parentHandle, /* in */ + TCS_KEY_HANDLE ephHandle, /* in */ + TCPA_ENTITY_TYPE entityType, /* in */ + TCPA_HMAC newAuthLink, /* in */ + UINT32 newAuthSize, /* in */ + BYTE * encNewAuth, /* in */ + UINT32 encDataSizeIn, /* in */ + BYTE * encDataIn, /* in */ + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * encDataSizeOut, /* out */ + BYTE ** encDataOut, /* out */ + TCPA_SALT_NONCE * saltNonce, /* out */ + TCPA_DIGEST * changeProof /* out */ + ) { + return TSPERR(TSS_E_NOTIMPL); +} diff --git a/src/tspi/rpc/tcstp/rpc_cmk.c b/src/tspi/rpc/tcstp/rpc_cmk.c new file mode 100644 index 0000000..ef8dfd5 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_cmk.c @@ -0,0 +1,393 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2007 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_CMK_SetRestrictions_TP(struct host_table_entry *hte, + TSS_CMK_DELEGATE restriction, /* in */ + TPM_AUTH *ownerAuth) /* in, out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_CMK_SETRESTRICTIONS; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &restriction, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 2, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_CMK_ApproveMA_TP(struct host_table_entry *hte, + TPM_DIGEST migAuthorityDigest, /* in */ + TPM_AUTH *ownerAuth, /* in, out */ + TPM_HMAC *migAuthorityApproval) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_CMK_APPROVEMA; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_DIGEST, 1, &migAuthorityDigest, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 2, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_DIGEST, 1, migAuthorityApproval, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_CMK_CreateKey_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE hWrappingKey, /* in */ + TPM_ENCAUTH *keyUsageAuth, /* in */ + TPM_HMAC *migAuthorityApproval, /* in */ + TPM_DIGEST *migAuthorityDigest, /* in */ + UINT32 *keyDataSize, /* in, out */ + BYTE **keyData, /* in, out */ + TPM_AUTH *pAuth) /* in, out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 8); + hte->comm.hdr.u.ordinal = TCSD_ORD_CMK_CREATEKEY; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hWrappingKey, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_ENCAUTH, 2, keyUsageAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_DIGEST, 3, migAuthorityApproval, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_DIGEST, 4, migAuthorityDigest, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 5, keyDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 6, *keyData, *keyDataSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (pAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 7, pAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + TPM_AUTH nullAuth; + + memset(&nullAuth, 0, sizeof(TPM_AUTH)); + if (setData(TCSD_PACKET_TYPE_AUTH, 7, &nullAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + free(*keyData); + *keyData = NULL; + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, keyDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + *keyData = (BYTE *)malloc(*keyDataSize); + if (*keyData == NULL) { + LogError("malloc of %u bytes failed.", *keyDataSize); + return TSPERR(TSS_E_OUTOFMEMORY); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *keyData, *keyDataSize, &hte->comm)) { + free(*keyData); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (pAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, 2, pAuth, 0, &hte->comm)) { + free(*keyData); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + } + } + + return result; +} + +TSS_RESULT +RPC_CMK_CreateTicket_TP(struct host_table_entry *hte, + UINT32 publicVerifyKeySize, /* in */ + BYTE *publicVerifyKey, /* in */ + TPM_DIGEST signedData, /* in */ + UINT32 sigValueSize, /* in */ + BYTE *sigValue, /* in */ + TPM_AUTH *ownerAuth, /* in, out */ + TPM_HMAC *sigTicket) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 7); + hte->comm.hdr.u.ordinal = TCSD_ORD_CMK_CREATETICKET; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &publicVerifyKeySize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 2, publicVerifyKey, publicVerifyKeySize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_DIGEST, 3, &signedData, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 4, &sigValueSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 5, sigValue, sigValueSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 6, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_DIGEST, 1, sigTicket, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_CMK_CreateBlob_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE hParentKey, /* in */ + TSS_MIGRATE_SCHEME migrationType, /* in */ + UINT32 migKeyAuthSize, /* in */ + BYTE *migKeyAuth, /* in */ + TPM_DIGEST pubSourceKeyDigest, /* in */ + UINT32 msaListSize, /* in */ + BYTE *msaList, /* in */ + UINT32 restrictTicketSize, /* in */ + BYTE *restrictTicket, /* in */ + UINT32 sigTicketSize, /* in */ + BYTE *sigTicket, /* in */ + UINT32 encDataSize, /* in */ + BYTE *encData, /* in */ + TPM_AUTH *pAuth, /* in, out */ + UINT32 *randomSize, /* out */ + BYTE **random, /* out */ + UINT32 *outDataSize, /* out */ + BYTE **outData) /* out */ +{ + TSS_RESULT result; + int i; + + initData(&hte->comm, 15); + hte->comm.hdr.u.ordinal = TCSD_ORD_CMK_CREATEBLOB; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hParentKey, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT16, 2, &migrationType, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 3, &migKeyAuthSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 4, migKeyAuth, migKeyAuthSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_DIGEST, 5, &pubSourceKeyDigest, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 6, &msaListSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 7, msaList, msaListSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 8, &restrictTicketSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 9, restrictTicket, restrictTicketSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 10, &sigTicketSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 11, sigTicket, sigTicketSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 12, &encDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 13, encData, encDataSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (pAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 14, pAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + TPM_AUTH nullAuth; + + memset(&nullAuth, 0, sizeof(TPM_AUTH)); + if (setData(TCSD_PACKET_TYPE_AUTH, 14, &nullAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (pAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, pAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, randomSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + *random = (BYTE *)malloc(*randomSize); + if (*random == NULL) { + LogError("malloc of %u bytes failed.", *randomSize); + return TSPERR(TSS_E_OUTOFMEMORY); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *random, *randomSize, &hte->comm)) { + free(*random); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, outDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + *outData = (BYTE *)malloc(*outDataSize); + if (*outData == NULL) { + LogError("malloc of %u bytes failed.", *outDataSize); + free(*random); + return TSPERR(TSS_E_OUTOFMEMORY); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outData, *outDataSize, &hte->comm)) { + free(*random); + free(*outData); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + } + + return result; +} + +TSS_RESULT +RPC_CMK_ConvertMigration_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE hParentHandle, /* in */ + TPM_CMK_AUTH restrictTicket, /* in */ + TPM_HMAC sigTicket, /* in */ + UINT32 keyDataSize, /* in */ + BYTE *keyData, /* in */ + UINT32 msaListSize, /* in */ + BYTE *msaList, /* in */ + UINT32 randomSize, /* in */ + BYTE *random, /* in */ + TPM_AUTH *pAuth, /* in, out */ + UINT32 *outDataSize, /* out */ + BYTE **outData) /* out */ +{ + TSS_RESULT result; + int i; + + initData(&hte->comm, 11); + hte->comm.hdr.u.ordinal = TCSD_ORD_CMK_CONVERTMIGRATION; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hParentHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 2, &restrictTicket, sizeof(restrictTicket), &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_DIGEST, 3, &sigTicket, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 4, &keyDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 5, keyData, keyDataSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 6, &msaListSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 7, msaList, msaListSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 8, &randomSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 9, random, randomSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (pAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 10, pAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + TPM_AUTH nullAuth; + + memset(&nullAuth, 0, sizeof(TPM_AUTH)); + if (setData(TCSD_PACKET_TYPE_AUTH, 10, &nullAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (pAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, pAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, outDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + *outData = (BYTE *)malloc(*outDataSize); + if (*outData == NULL) { + LogError("malloc of %u bytes failed.", *outDataSize); + return TSPERR(TSS_E_OUTOFMEMORY); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outData, *outDataSize, &hte->comm)) { + free(*outData); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + } + + return result; +} + diff --git a/src/tspi/rpc/tcstp/rpc_context.c b/src/tspi/rpc/tcstp/rpc_context.c new file mode 100644 index 0000000..95fafbe --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_context.c @@ -0,0 +1,80 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_OpenContext_TP(struct host_table_entry* hte, + UINT32* tpm_version, + TCS_CONTEXT_HANDLE* tcsContext) +{ + TSS_RESULT result; + + initData(&hte->comm, 0); + hte->comm.hdr.u.ordinal = TCSD_ORD_OPENCONTEXT; + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + LogDebugFn("Received TCS Context: 0x%x", *tcsContext); + + if (getData(TCSD_PACKET_TYPE_UINT32, 1, tpm_version, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_CloseContext_TP(struct host_table_entry *hte) +{ + TSS_RESULT result; + + initData(&hte->comm, 1); + hte->comm.hdr.u.ordinal = TCSD_ORD_CLOSECONTEXT; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_FreeMemory_TP(struct host_table_entry *hte, + BYTE * pMemory) /* in */ +{ + free(pMemory); + + return TSS_SUCCESS; +} diff --git a/src/tspi/rpc/tcstp/rpc_counter.c b/src/tspi/rpc/tcstp/rpc_counter.c new file mode 100644 index 0000000..d6b2b37 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_counter.c @@ -0,0 +1,204 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2007 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_ReadCounter_TP(struct host_table_entry* hte, + TSS_COUNTER_ID idCounter, /* in */ + TPM_COUNTER_VALUE* counterValue) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_READCOUNTER; + LogDebugFn("IN: TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &idCounter, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_COUNTER_VALUE, 0, counterValue, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_CreateCounter_TP(struct host_table_entry* hte, + UINT32 LabelSize, /* in (=4) */ + BYTE* pLabel, /* in */ + TPM_ENCAUTH CounterAuth, /* in */ + TPM_AUTH* pOwnerAuth, /* in, out */ + TSS_COUNTER_ID* idCounter, /* out */ + TPM_COUNTER_VALUE* counterValue) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 5); + hte->comm.hdr.u.ordinal = TCSD_ORD_CREATECOUNTER; + LogDebugFn("IN: TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &LabelSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 2, &pLabel, LabelSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_ENCAUTH, 3, &CounterAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 4, pOwnerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, pOwnerAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, 1, idCounter, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_COUNTER_VALUE, 2, counterValue, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } +done: + return result; +} + +TSS_RESULT +RPC_IncrementCounter_TP(struct host_table_entry* hte, + TSS_COUNTER_ID idCounter, /* in */ + TPM_AUTH* pCounterAuth, /* in, out */ + TPM_COUNTER_VALUE* counterValue) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_INCREMENTCOUNTER; + LogDebugFn("IN: TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &idCounter, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 2, pCounterAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, pCounterAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_COUNTER_VALUE, 1, counterValue, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } +done: + return result; +} + +TSS_RESULT +RPC_ReleaseCounter_TP(struct host_table_entry* hte, + TSS_COUNTER_ID idCounter, /* in */ + TPM_AUTH* pCounterAuth) /* in, out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_RELEASECOUNTER; + LogDebugFn("IN: TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &idCounter, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 2, pCounterAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, pCounterAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_ReleaseCounterOwner_TP(struct host_table_entry* hte, + TSS_COUNTER_ID idCounter, /* in */ + TPM_AUTH* pOwnerAuth) /* in, out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_RELEASECOUNTEROWNER; + LogDebugFn("IN: TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &idCounter, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 2, pOwnerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, pOwnerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_daa.c b/src/tspi/rpc/tcstp/rpc_daa.c new file mode 100644 index 0000000..e48d30e --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_daa.c @@ -0,0 +1,184 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_DaaJoin_TP(struct host_table_entry *hte, + TPM_HANDLE handle, // in + BYTE stage, // in + UINT32 inputSize0, // in + BYTE* inputData0, // in + UINT32 inputSize1, // in + BYTE* inputData1, // in + TPM_AUTH* ownerAuth, // in/out + UINT32* outputSize, // out + BYTE** outputData) // out +{ + TSS_RESULT result; + UINT32 i; + + LogDebugFn("stage=%d", stage); + initData(&hte->comm, 8); + hte->comm.hdr.u.ordinal = TCSD_ORD_DAAJOIN; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &handle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_BYTE, 2, &stage, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 3, &inputSize0, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + LogDebugFn("inputSize0=<network>=%d <host>=%d", inputSize0, inputSize0); + if (setData(TCSD_PACKET_TYPE_PBYTE, 4, inputData0, inputSize0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 5, &inputSize1, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + LogDebugFn("inputSize1=<network>=%d <host>=%d", inputSize1, inputSize1); + if (setData(TCSD_PACKET_TYPE_PBYTE, 6, inputData1, inputSize1, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if( ownerAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 7, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + LogDebugFn("getData outputSize"); + + if( ownerAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, ownerAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, outputSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *outputData = (BYTE *) malloc(*outputSize); + if (*outputData == NULL) { + LogError("malloc of %u bytes failed.", *outputSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + LogDebugFn("getData outputData (outputSize=%u)", *outputSize); + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outputData, *outputSize, &hte->comm)) { + free(*outputData); + *outputData = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + +done: + LogDebugFn("result=%u", result); + return result; +} + +TSS_RESULT +RPC_DaaSign_TP(struct host_table_entry *hte, + TPM_HANDLE handle, // in + BYTE stage, // in + UINT32 inputSize0, // in + BYTE* inputData0, // in + UINT32 inputSize1, // in + BYTE* inputData1, // in + TPM_AUTH* ownerAuth, // in/out + UINT32* outputSize, // out + BYTE** outputData) // out +{ + TSS_RESULT result; + UINT32 i; + + LogDebugFn("stage=%d", stage); + initData(&hte->comm, 8); + hte->comm.hdr.u.ordinal = TCSD_ORD_DAASIGN; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &handle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_BYTE, 2, &stage, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 3, &inputSize0, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + LogDebugFn("inputSize0=<network>=%d <host>=%d", inputSize0, inputSize0); + if (setData(TCSD_PACKET_TYPE_PBYTE, 4, inputData0, inputSize0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 5, &inputSize1, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + LogDebugFn("inputSize1=<network>=%d <host>=%d", inputSize1, inputSize1); + if (setData(TCSD_PACKET_TYPE_PBYTE, 6, inputData1, inputSize1, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if( ownerAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 7, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + LogDebugFn("sendTCSDPacket: 0x%x", (int)hte); + result = sendTCSDPacket(hte); + // + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + // + if (result == TSS_SUCCESS) { + i = 0; + LogDebugFn("getData outputSize"); + + if( ownerAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, ownerAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, outputSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *outputData = (BYTE *) malloc(*outputSize); + if (*outputData == NULL) { + LogError("malloc of %u bytes failed.", *outputSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + LogDebugFn("getData outputData (outputSize=%d)", *outputSize); + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outputData, *outputSize, &hte->comm)) { + free(*outputData); + *outputData = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + +done: + LogDebugFn("result=%u", result); + return result; +} + diff --git a/src/tspi/rpc/tcstp/rpc_delegate.c b/src/tspi/rpc/tcstp/rpc_delegate.c new file mode 100644 index 0000000..d4b6ac2 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_delegate.c @@ -0,0 +1,452 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2007 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_Delegate_Manage_TP(struct host_table_entry *hte, + TPM_FAMILY_ID familyID, /* in */ + TPM_FAMILY_OPERATION opFlag, /* in */ + UINT32 opDataSize, /* in */ + BYTE *opData, /* in */ + TPM_AUTH *ownerAuth, /* in/out */ + UINT32 *retDataSize, /* out */ + BYTE **retData) /* out */ +{ + TSS_RESULT result; + int i; + + initData(&hte->comm, 6); + hte->comm.hdr.u.ordinal = TCSD_ORD_DELEGATE_MANAGE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &familyID, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &opFlag, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 3, &opDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 4, opData, opDataSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (ownerAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 5, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + TPM_AUTH nullAuth; + + memset(&nullAuth, 0, sizeof(TPM_AUTH)); + if (setData(TCSD_PACKET_TYPE_AUTH, 5, &nullAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (ownerAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, retDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + *retData = (BYTE *)malloc(*retDataSize); + if (*retData == NULL) { + LogError("malloc of %u bytes failed.", *retDataSize); + return TSPERR(TSS_E_OUTOFMEMORY); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *retData, *retDataSize, &hte->comm)) { + free(*retData); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + } + + return result; +} + +TSS_RESULT +RPC_Delegate_CreateKeyDelegation_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE hKey, /* in */ + UINT32 publicInfoSize, /* in */ + BYTE *publicInfo, /* in */ + TPM_ENCAUTH *encDelAuth, /* in */ + TPM_AUTH *keyAuth, /* in/out */ + UINT32 *blobSize, /* out */ + BYTE **blob) /* out */ +{ + TSS_RESULT result; + int i; + + initData(&hte->comm, 8); + hte->comm.hdr.u.ordinal = TCSD_ORD_DELEGATE_CREATEKEYDELEGATION; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &publicInfoSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, publicInfo, publicInfoSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_ENCAUTH, 4, encDelAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (keyAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 5, keyAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + TPM_AUTH nullAuth; + + memset(&nullAuth, 0, sizeof(TPM_AUTH)); + if (setData(TCSD_PACKET_TYPE_AUTH, 5, &nullAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (keyAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, keyAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, blobSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + *blob = (BYTE *)malloc(*blobSize); + if (*blob == NULL) { + LogError("malloc of %u bytes failed.", *blobSize); + return TSPERR(TSS_E_OUTOFMEMORY); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *blob, *blobSize, &hte->comm)) { + free(*blob); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + } + + return result; +} + +TSS_RESULT +RPC_Delegate_CreateOwnerDelegation_TP(struct host_table_entry *hte, + TSS_BOOL increment, /* in */ + UINT32 publicInfoSize, /* in */ + BYTE *publicInfo, /* in */ + TPM_ENCAUTH *encDelAuth, /* in */ + TPM_AUTH *ownerAuth, /* in/out */ + UINT32 *blobSize, /* out */ + BYTE **blob) /* out */ +{ + TSS_RESULT result; + int i; + + initData(&hte->comm, 8); + hte->comm.hdr.u.ordinal = TCSD_ORD_DELEGATE_CREATEOWNERDELEGATION; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_BOOL, 1, &increment, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &publicInfoSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, publicInfo, publicInfoSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_ENCAUTH, 4, encDelAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (ownerAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 5, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + TPM_AUTH nullAuth; + + memset(&nullAuth, 0, sizeof(TPM_AUTH)); + if (setData(TCSD_PACKET_TYPE_AUTH, 5, &nullAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (ownerAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, blobSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + *blob = (BYTE *)malloc(*blobSize); + if (*blob == NULL) { + LogError("malloc of %u bytes failed.", *blobSize); + return TSPERR(TSS_E_OUTOFMEMORY); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *blob, *blobSize, &hte->comm)) { + free(*blob); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + } + + return result; +} + +TSS_RESULT +RPC_Delegate_LoadOwnerDelegation_TP(struct host_table_entry *hte, + TPM_DELEGATE_INDEX index, /* in */ + UINT32 blobSize, /* in */ + BYTE *blob, /* in */ + TPM_AUTH *ownerAuth) /* in/out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 5); + hte->comm.hdr.u.ordinal = TCSD_ORD_DELEGATE_LOADOWNERDELEGATION; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &index, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &blobSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, blob, blobSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (ownerAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 4, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + TPM_AUTH nullAuth; + + memset(&nullAuth, 0, sizeof(TPM_AUTH)); + if (setData(TCSD_PACKET_TYPE_AUTH, 4, &nullAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (ownerAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + } + + return result; +} + +TSS_RESULT +RPC_Delegate_ReadTable_TP(struct host_table_entry *hte, + UINT32 *familyTableSize, /* out */ + BYTE **familyTable, /* out */ + UINT32 *delegateTableSize, /* out */ + BYTE **delegateTable) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 1); + hte->comm.hdr.u.ordinal = TCSD_ORD_DELEGATE_READTABLE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, familyTableSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + *familyTable = (BYTE *)malloc(*familyTableSize); + if (*familyTable == NULL) { + LogError("malloc of %u bytes failed.", *familyTableSize); + return TSPERR(TSS_E_OUTOFMEMORY); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *familyTable, *familyTableSize, &hte->comm)) { + free(*familyTable); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + if (getData(TCSD_PACKET_TYPE_UINT32, 2, delegateTableSize, 0, &hte->comm)) { + free(*familyTable); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + *delegateTable = (BYTE *)malloc(*delegateTableSize); + if (*delegateTable == NULL) { + free(*familyTable); + LogError("malloc of %u bytes failed.", *delegateTableSize); + return TSPERR(TSS_E_OUTOFMEMORY); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 3, *delegateTable, *delegateTableSize, &hte->comm)) { + free(*familyTable); + free(*delegateTable); + return TSPERR(TSS_E_INTERNAL_ERROR); + } + } + + return result; +} + +TSS_RESULT +RPC_Delegate_UpdateVerificationCount_TP(struct host_table_entry *hte, + UINT32 inputSize, /* in */ + BYTE *input, /* in */ + TPM_AUTH *ownerAuth, /* in/out */ + UINT32 *outputSize, /* out */ + BYTE **output) /* out */ +{ + TSS_RESULT result; + int i; + + initData(&hte->comm, 4); + hte->comm.hdr.u.ordinal = TCSD_ORD_DELEGATE_UPDATEVERIFICATIONCOUNT; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &inputSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 2, input, inputSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (ownerAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 3, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + TPM_AUTH nullAuth; + + memset(&nullAuth, 0, sizeof(TPM_AUTH)); + if (setData(TCSD_PACKET_TYPE_AUTH, 3, &nullAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (ownerAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, outputSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + *output = (BYTE *)malloc(*outputSize); + if (*output == NULL) { + LogError("malloc of %u bytes failed.", *outputSize); + return TSPERR(TSS_E_OUTOFMEMORY); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *output, *outputSize, &hte->comm)) { + free(*output); + output = NULL; + return TSPERR(TSS_E_INTERNAL_ERROR); + } + } + + return result; +} + +TSS_RESULT +RPC_Delegate_VerifyDelegation_TP(struct host_table_entry *hte, + UINT32 delegateSize, /* in */ + BYTE *delegate) /* in */ +{ + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_DELEGATE_VERIFYDELEGATION; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &delegateSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 2, delegate, delegateSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_DSAP_TP(struct host_table_entry *hte, + TPM_ENTITY_TYPE entityType, /* in */ + TCS_KEY_HANDLE keyHandle, /* in */ + TPM_NONCE *nonceOddDSAP, /* in */ + UINT32 entityValueSize, /* in */ + BYTE * entityValue, /* in */ + TCS_AUTHHANDLE *authHandle, /* out */ + TPM_NONCE *nonceEven, /* out */ + TPM_NONCE *nonceEvenDSAP) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 6); + hte->comm.hdr.u.ordinal = TCSD_ORD_DSAP; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT16, 1, &entityType, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &keyHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 3, nonceOddDSAP, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 4, &entityValueSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 5, entityValue, entityValueSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, authHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_NONCE, 1, nonceEven, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_NONCE, 2, nonceEvenDSAP, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_dir.c b/src/tspi/rpc/tcstp/rpc_dir.c new file mode 100644 index 0000000..12f2d4f --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_dir.c @@ -0,0 +1,89 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_DirWriteAuth_TP(struct host_table_entry *hte, + TCPA_DIRINDEX dirIndex, /* in */ + TCPA_DIRVALUE *newContents, /* in */ + TPM_AUTH * ownerAuth /* in, out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 4); + hte->comm.hdr.u.ordinal = TCSD_ORD_DIRWRITEAUTH; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &dirIndex, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_DIGEST, 2, newContents, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 3, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_DirRead_TP(struct host_table_entry *hte, + TCPA_DIRINDEX dirIndex, /* in */ + TCPA_DIRVALUE * dirValue /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_DIRREAD; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &dirIndex, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (hte->comm.hdr.u.result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_DIGEST, 0, dirValue, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_ek.c b/src/tspi/rpc/tcstp/rpc_ek.c new file mode 100644 index 0000000..c95753d --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_ek.c @@ -0,0 +1,304 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2007 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_CreateEndorsementKeyPair_TP(struct host_table_entry *hte, + TCPA_NONCE antiReplay, /* in */ + UINT32 endorsementKeyInfoSize, /* in */ + BYTE * endorsementKeyInfo, /* in */ + UINT32 * endorsementKeySize, /* out */ + BYTE ** endorsementKey, /* out */ + TCPA_DIGEST * checksum /* out */ + ) { + + TSS_RESULT result; + + initData(&hte->comm, 4); + hte->comm.hdr.u.ordinal = TCSD_ORD_CREATEENDORSEMENTKEYPAIR; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &endorsementKeyInfoSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, endorsementKeyInfo, endorsementKeyInfoSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, endorsementKeySize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *endorsementKey = (BYTE *) malloc(*endorsementKeySize); + if (*endorsementKey == NULL) { + LogError("malloc of %u bytes failed.", *endorsementKeySize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *endorsementKey, *endorsementKeySize, &hte->comm)) { + free(*endorsementKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_DIGEST, 2, &(checksum->digest), 0, &hte->comm)) { + free(*endorsementKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} + +TSS_RESULT +RPC_ReadPubek_TP(struct host_table_entry *hte, + TCPA_NONCE antiReplay, /* in */ + UINT32 * pubEndorsementKeySize, /* out */ + BYTE ** pubEndorsementKey, /* out */ + TCPA_DIGEST * checksum /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_READPUBEK; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + /* &hte->comm.numParms = 2; */ + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, pubEndorsementKeySize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *pubEndorsementKey = (BYTE *) malloc(*pubEndorsementKeySize); + if (*pubEndorsementKey == NULL) { + LogError("malloc of %u bytes failed.", *pubEndorsementKeySize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *pubEndorsementKey, *pubEndorsementKeySize, &hte->comm)) { + free(*pubEndorsementKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_DIGEST, 2, &(checksum->digest), 0, &hte->comm)) { + free(*pubEndorsementKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } +done: + return result; +} + +TSS_RESULT +RPC_DisablePubekRead_TP(struct host_table_entry *hte, + TPM_AUTH * ownerAuth /* in, out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_DISABLEPUBEKREAD; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (setData(TCSD_PACKET_TYPE_AUTH, 1, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_OwnerReadPubek_TP(struct host_table_entry *hte, + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * pubEndorsementKeySize, /* out */ + BYTE ** pubEndorsementKey /* out */ + ) { + + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_OWNERREADPUBEK; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 1, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)){ + free(*pubEndorsementKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + if (getData(TCSD_PACKET_TYPE_UINT32, 1, pubEndorsementKeySize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *pubEndorsementKey = (BYTE *) malloc(*pubEndorsementKeySize); + if (*pubEndorsementKey == NULL) { + LogError("malloc of %u bytes failed.", *pubEndorsementKeySize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *pubEndorsementKey, *pubEndorsementKeySize, &hte->comm)) { + free(*pubEndorsementKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + +done: + return result; +} + +#ifdef TSS_BUILD_TSS12 +TSS_RESULT +RPC_CreateRevocableEndorsementKeyPair_TP(struct host_table_entry *hte, + TPM_NONCE antiReplay, /* in */ + UINT32 endorsementKeyInfoSize,/* in */ + BYTE * endorsementKeyInfo, /* in */ + TSS_BOOL genResetAuth, /* in */ + TPM_DIGEST * eKResetAuth, /* in, out */ + UINT32 * endorsementKeySize, /* out */ + BYTE ** endorsementKey, /* out */ + TPM_DIGEST * checksum) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 6); + hte->comm.hdr.u.ordinal = TCSD_ORD_CREATEREVOCABLEENDORSEMENTKEYPAIR; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &endorsementKeyInfoSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, endorsementKeyInfo, endorsementKeyInfoSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_BOOL, 4, &genResetAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_DIGEST, 5, eKResetAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_DIGEST, 0, &(eKResetAuth->digest), 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, 1, endorsementKeySize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *endorsementKey = (BYTE *) malloc(*endorsementKeySize); + if (*endorsementKey == NULL) { + LogError("malloc of %u bytes failed.", *endorsementKeySize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *endorsementKey, *endorsementKeySize, &hte->comm)) { + free(*endorsementKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_DIGEST, 3, &(checksum->digest), 0, &hte->comm)) { + free(*endorsementKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} + +TSS_RESULT +RPC_RevokeEndorsementKeyPair_TP(struct host_table_entry *hte, + TPM_DIGEST *EKResetAuth) /* in */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_REVOKEENDORSEMENTKEYPAIR; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_DIGEST, 1, EKResetAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} +#endif diff --git a/src/tspi/rpc/tcstp/rpc_evlog.c b/src/tspi/rpc/tcstp/rpc_evlog.c new file mode 100644 index 0000000..7256795 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_evlog.c @@ -0,0 +1,231 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_LogPcrEvent_TP(struct host_table_entry *hte, + TSS_PCR_EVENT Event, /* in */ + UINT32 * pNumber /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_LOGPCREVENT; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (setData(TCSD_PACKET_TYPE_PCR_EVENT, 1, &Event, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, pNumber, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_GetPcrEvent_TP(struct host_table_entry *hte, + UINT32 PcrIndex, /* in */ + UINT32 * pNumber, /* in, out */ + TSS_PCR_EVENT ** ppEvent /* out */ + ) { + TSS_RESULT result; + BYTE lengthOnly = (ppEvent == NULL) ? TRUE : FALSE; + + initData(&hte->comm, 4); + hte->comm.hdr.u.ordinal = TCSD_ORD_GETPCREVENT; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &PcrIndex, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (setData(TCSD_PACKET_TYPE_UINT32, 2, pNumber, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (setData(TCSD_PACKET_TYPE_BYTE, 3, &lengthOnly, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, pNumber, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + if (ppEvent) { + *ppEvent = malloc(sizeof(TSS_PCR_EVENT)); + if (*ppEvent == NULL) { + LogError("malloc of %zd bytes failed.", + sizeof(TSS_PCR_EVENT)); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_PCR_EVENT, 1, *ppEvent, 0, &hte->comm)) { + free(*ppEvent); + *ppEvent = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + } + +done: + return result; +} + +TSS_RESULT +RPC_GetPcrEventsByPcr_TP(struct host_table_entry *hte, + UINT32 PcrIndex, /* in */ + UINT32 FirstEvent, /* in */ + UINT32 * pEventCount, /* in, out */ + TSS_PCR_EVENT ** ppEvents /* out */ + ) { + TSS_RESULT result; + UINT32 i, j; + + initData(&hte->comm, 4); + hte->comm.hdr.u.ordinal = TCSD_ORD_GETPCREVENTBYPCR; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &PcrIndex, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &FirstEvent, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (setData(TCSD_PACKET_TYPE_UINT32, 3, pEventCount, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, pEventCount, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + if (*pEventCount > 0) { + *ppEvents = calloc_tspi(hte->tspContext, + sizeof(TSS_PCR_EVENT) * (*pEventCount)); + if (*ppEvents == NULL) { + LogError("malloc of %zd bytes failed.", sizeof(TSS_PCR_EVENT) * (*pEventCount)); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + + i = 1; + for (j = 0; j < (*pEventCount); j++) { + if (getData(TCSD_PACKET_TYPE_PCR_EVENT, i++, &((*ppEvents)[j]), 0, &hte->comm)) { + free(*ppEvents); + *ppEvents = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + } else { + *ppEvents = NULL; + } + } + +done: + return result; +} + +TSS_RESULT +RPC_GetPcrEventLog_TP(struct host_table_entry *hte, + UINT32 * pEventCount, /* out */ + TSS_PCR_EVENT ** ppEvents /* out */ + ) { + TSS_RESULT result; + int i, j; + + initData(&hte->comm, 1); + hte->comm.hdr.u.ordinal = TCSD_ORD_GETPCREVENTLOG; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, pEventCount, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + if (*pEventCount > 0) { + *ppEvents = calloc_tspi(hte->tspContext, + sizeof(TSS_PCR_EVENT) * (*pEventCount)); + if (*ppEvents == NULL) { + LogError("malloc of %zd bytes failed.", + sizeof(TSS_PCR_EVENT) * (*pEventCount)); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + + i = 1; + for (j = 0; (UINT32)j < (*pEventCount); j++) { + if (getData(TCSD_PACKET_TYPE_PCR_EVENT, i++, &((*ppEvents)[j]), 0, &hte->comm)) { + free(*ppEvents); + *ppEvents = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + } else { + *ppEvents = NULL; + } + } + +done: + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_key.c b/src/tspi/rpc/tcstp/rpc_key.c new file mode 100644 index 0000000..0c983af --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_key.c @@ -0,0 +1,350 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2007 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_LoadKeyByBlob_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE hUnwrappingKey, /* in */ + UINT32 cWrappedKeyBlobSize, /* in */ + BYTE * rgbWrappedKeyBlob, /* in */ + TPM_AUTH * pAuth, /* in, out */ + TCS_KEY_HANDLE * phKeyTCSI, /* out */ + TCS_KEY_HANDLE * phKeyHMAC) /* out */ +{ + TSS_RESULT result; + int i; + + initData(&hte->comm, 5); + hte->comm.hdr.u.ordinal = TCSD_ORD_LOADKEYBYBLOB; + LogDebugFn("IN: TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hUnwrappingKey, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &cWrappedKeyBlobSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, rgbWrappedKeyBlob, cWrappedKeyBlobSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (pAuth != NULL) { + if (setData(TCSD_PACKET_TYPE_AUTH, 4, pAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (pAuth != NULL) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, pAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, phKeyTCSI, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_UINT32, i++, phKeyHMAC, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + + LogDebugFn("OUT: TCS key handle: 0x%x, TPM key slot: 0x%x", *phKeyTCSI, + *phKeyHMAC); + } + + return result; +} + +TSS_RESULT +RPC_EvictKey_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE hKey) /* in */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_EVICTKEY; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_CreateWrapKey_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE hWrappingKey, /* in */ + TCPA_ENCAUTH *KeyUsageAuth, /* in */ + TCPA_ENCAUTH *KeyMigrationAuth, /* in */ + UINT32 keyInfoSize, /* in */ + BYTE * keyInfo, /* in */ + UINT32 * keyDataSize, /* out */ + BYTE ** keyData, /* out */ + TPM_AUTH * pAuth) /* in, out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 7); + hte->comm.hdr.u.ordinal = TCSD_ORD_CREATEWRAPKEY; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hWrappingKey, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_ENCAUTH, 2, KeyUsageAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_ENCAUTH, 3, KeyMigrationAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 4, &keyInfoSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 5, keyInfo, keyInfoSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (pAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 6, pAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, keyDataSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *keyData = (BYTE *) malloc(*keyDataSize); + if (*keyData == NULL) { + LogError("malloc of %u bytes failed.", *keyDataSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *keyData, *keyDataSize, &hte->comm)) { + free(*keyData); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (pAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, 2, pAuth, 0, &hte->comm)) { + free(*keyData); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + } + +done: + return result; +} + +TSS_RESULT +RPC_GetPubKey_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE hKey, /* in */ + TPM_AUTH * pAuth, /* in, out */ + UINT32 * pcPubKeySize, /* out */ + BYTE ** prgbPubKey) /* out */ +{ + TSS_RESULT result; + int i; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_GETPUBKEY; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (pAuth != NULL) { + if (setData(TCSD_PACKET_TYPE_AUTH, 2, pAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + i = 0; + if (result == TSS_SUCCESS) { + if (pAuth != NULL) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, pAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcPubKeySize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *prgbPubKey = (BYTE *) malloc(*pcPubKeySize); + if (*prgbPubKey == NULL) { + LogError("malloc of %u bytes failed.", *pcPubKeySize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbPubKey, *pcPubKeySize, &hte->comm)) { + free(*prgbPubKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} + +TSS_RESULT +RPC_TerminateHandle_TP(struct host_table_entry *hte, + TCS_AUTHHANDLE handle) /* in */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_TERMINATEHANDLE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &handle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_OwnerReadInternalPub_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE hKey, /* in */ + TPM_AUTH * pOwnerAuth, /* in, out */ + UINT32 * punPubKeySize, /* out */ + BYTE ** ppbPubKeyData) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_OWNERREADINTERNALPUB; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (pOwnerAuth != NULL) { + if (setData(TCSD_PACKET_TYPE_AUTH, 2, pOwnerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, pOwnerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_UINT32, 1, punPubKeySize, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + + *ppbPubKeyData = (BYTE *) malloc(*punPubKeySize); + if (*ppbPubKeyData == NULL) { + LogError("malloc of %u bytes failed.", *punPubKeySize); + return TSPERR(TSS_E_OUTOFMEMORY); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *ppbPubKeyData, *punPubKeySize, + &hte->comm)) { + free(*ppbPubKeyData); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + + return result; +} + +/* TSS 1.2-only interfaces */ +#ifdef TSS_BUILD_TSS12 +TSS_RESULT +RPC_KeyControlOwner_TP(struct host_table_entry *hte, // in + TCS_KEY_HANDLE hKey, // in + UINT32 ulPublicInfoLength, // in + BYTE* rgbPublicInfo, // in + UINT32 attribName, // in + TSS_BOOL attribValue, // in + TPM_AUTH* pOwnerAuth, // in, out + TSS_UUID* pUuidData) // out + +{ + TSS_RESULT result; + + initData(&hte->comm, 7); + hte->comm.hdr.u.ordinal = TCSD_ORD_KEYCONTROLOWNER; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &ulPublicInfoLength, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, rgbPublicInfo, ulPublicInfoLength, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 4, &attribName, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_BOOL, 5, &attribValue, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (pOwnerAuth != NULL) { + if (setData(TCSD_PACKET_TYPE_AUTH, 6, pOwnerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, pOwnerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_UUID, 1, pUuidData, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} +#endif diff --git a/src/tspi/rpc/tcstp/rpc_maint.c b/src/tspi/rpc/tcstp/rpc_maint.c new file mode 100644 index 0000000..75dfc09 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_maint.c @@ -0,0 +1,250 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_CreateMaintenanceArchive_TP(struct host_table_entry *hte, + TSS_BOOL generateRandom, /* in */ + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * randomSize, /* out */ + BYTE ** random, /* out */ + UINT32 * archiveSize, /* out */ + BYTE ** archive /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_CREATEMAINTENANCEARCHIVE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_BOOL, 1, &generateRandom, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 2, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_UINT32, 1, randomSize, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + + if (*randomSize > 0) { + *random = malloc(*randomSize); + if (*random == NULL) { + LogError("malloc of %u bytes failed.", *randomSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *random, *randomSize, &hte->comm)) { + free(*random); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } else { + *random = NULL; + } + + /* Assume all elements are in the list, even when *randomSize == 0. */ + if (getData(TCSD_PACKET_TYPE_UINT32, 3, archiveSize, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + + if (*archiveSize > 0) { + *archive = malloc(*archiveSize); + if (*archive == NULL) { + free(*random); + LogError("malloc of %u bytes failed.", *archiveSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_PBYTE, 4, *archive, *archiveSize, &hte->comm)) { + free(*random); + free(*archive); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } else { + *archive = NULL; + } + } +done: + return result; +} + +TSS_RESULT +RPC_LoadMaintenanceArchive_TP(struct host_table_entry *hte, + UINT32 dataInSize, /* in */ + BYTE * dataIn, /* in */ + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * dataOutSize, /* out */ + BYTE ** dataOut /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 4); + hte->comm.hdr.u.ordinal = TCSD_ORD_LOADMAINTENANCEARCHIVE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &dataInSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 2, &dataIn, dataInSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 3, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_UINT32, 1, dataOutSize, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + + if (*dataOutSize > 0) { + *dataOut = malloc(*dataOutSize); + if (*dataOut == NULL) { + LogError("malloc of %u bytes failed.", *dataOutSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *dataOut, *dataOutSize, &hte->comm)) { + free(*dataOut); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } else { + *dataOut = NULL; + } + } +done: + return result; +} + +TSS_RESULT +RPC_KillMaintenanceFeature_TP(struct host_table_entry *hte, + TPM_AUTH * ownerAuth /* in , out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_KILLMAINTENANCEFEATURE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 1, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_LoadManuMaintPub_TP(struct host_table_entry *hte, + TCPA_NONCE antiReplay, /* in */ + UINT32 PubKeySize, /* in */ + BYTE * PubKey, /* in */ + TCPA_DIGEST * checksum /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 4); + hte->comm.hdr.u.ordinal = TCSD_ORD_LOADMANUFACTURERMAINTENANCEPUB; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &PubKeySize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, PubKey, PubKeySize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_DIGEST, 0, checksum, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_ReadManuMaintPub_TP(struct host_table_entry *hte, + TCPA_NONCE antiReplay, /* in */ + TCPA_DIGEST * checksum /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_READMANUFACTURERMAINTENANCEPUB; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_DIGEST, 0, checksum, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_migration.c b/src/tspi/rpc/tcstp/rpc_migration.c new file mode 100644 index 0000000..43f7f27 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_migration.c @@ -0,0 +1,270 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_CreateMigrationBlob_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE parentHandle, /* in */ + TSS_MIGRATE_SCHEME migrationType, /* in */ + UINT32 MigrationKeyAuthSize, /* in */ + BYTE * MigrationKeyAuth, /* in */ + UINT32 encDataSize, /* in */ + BYTE * encData, /* in */ + TPM_AUTH * parentAuth, /* in, out */ + TPM_AUTH * entityAuth, /* in, out */ + UINT32 * randomSize, /* out */ + BYTE ** random, /* out */ + UINT32 * outDataSize, /* out */ + BYTE ** outData /* out */ + ) { + TSS_RESULT result; + TPM_AUTH null_auth; + UINT32 i; + + initData(&hte->comm, 9); + memset(&null_auth, 0, sizeof(TPM_AUTH)); + + hte->comm.hdr.u.ordinal = TCSD_ORD_CREATEMIGRATIONBLOB; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + i = 0; + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &parentHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT16, i++, &migrationType, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &MigrationKeyAuthSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, i++, MigrationKeyAuth, MigrationKeyAuthSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &encDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, i++, encData, encDataSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (parentAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, i++, parentAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + if (setData(TCSD_PACKET_TYPE_AUTH, i++, entityAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (parentAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, parentAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_AUTH, i++, entityAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_UINT32, i++, randomSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + if (*randomSize > 0) { + *random = (BYTE *)malloc(*randomSize); + if (*random == NULL) { + LogError("malloc of %u bytes failed.", *randomSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *random, *randomSize, &hte->comm)) { + free(*random); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + + if (getData(TCSD_PACKET_TYPE_UINT32, i++, outDataSize, 0, &hte->comm)) { + if (*randomSize > 0) + free(*random); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *outData = (BYTE *)malloc(*outDataSize); + if (*outData == NULL) { + if (*randomSize > 0) + free(*random); + LogError("malloc of %u bytes failed.", *outDataSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outData, *outDataSize, &hte->comm)) { + if (*randomSize > 0) + free(*random); + free(*outData); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + +done: + return result; +} + +TSS_RESULT +RPC_ConvertMigrationBlob_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE parentHandle, /* in */ + UINT32 inDataSize, /* in */ + BYTE * inData, /* in */ + UINT32 randomSize, /* in */ + BYTE * random, /* in */ + TPM_AUTH * parentAuth, /* in, out */ + UINT32 * outDataSize, /* out */ + BYTE ** outData /* out */ + ) { + TSS_RESULT result; + UINT32 i; + + initData(&hte->comm, 7); + hte->comm.hdr.u.ordinal = TCSD_ORD_CONVERTMIGRATIONBLOB; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &parentHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &inDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, inData, inDataSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 4, &randomSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 5, random, randomSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (parentAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 6, parentAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (parentAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, parentAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + + if (getData(TCSD_PACKET_TYPE_UINT32, i++, outDataSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *outData = (BYTE *)malloc(*outDataSize); + if (*outData == NULL) { + LogError("malloc of %u bytes failed.", *outDataSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outData, *outDataSize, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + +done: + return result; +} + +TSS_RESULT +RPC_AuthorizeMigrationKey_TP(struct host_table_entry *hte, + TSS_MIGRATE_SCHEME migrateScheme, /* in */ + UINT32 MigrationKeySize, /* in */ + BYTE * MigrationKey, /* in */ + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * MigrationKeyAuthSize, /* out */ + BYTE ** MigrationKeyAuth /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 5); + hte->comm.hdr.u.ordinal = TCSD_ORD_AUTHORIZEMIGRATIONKEY; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT16, 1, &migrateScheme, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &MigrationKeySize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, MigrationKey, MigrationKeySize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 4, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, 1, MigrationKeyAuthSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *MigrationKeyAuth = (BYTE *)malloc(*MigrationKeyAuthSize); + if (*MigrationKeyAuth == NULL) { + LogError("malloc of %u bytes failed.", *MigrationKeyAuthSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *MigrationKeyAuth, *MigrationKeyAuthSize, + &hte->comm)) { + free(*MigrationKeyAuth); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + +done: + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_nv.c b/src/tspi/rpc/tcstp/rpc_nv.c new file mode 100644 index 0000000..faf44e5 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_nv.c @@ -0,0 +1,315 @@ +/* + * The Initial Developer of the Original Code is Intel Corporation. + * Portions created by Intel Corporation are Copyright (C) 2007 Intel Corporation. + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the Common Public License as published by + * IBM Corporation; either version 1 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Common Public License for more details. + * + * You should have received a copy of the Common Public License + * along with this program; if not, a copy can be viewed at + * http://www.opensource.org/licenses/cpl1.0.php. + * + * trousers - An open source TCG Software Stack + * + * Author: james.xu@intel.com Rossey.liu@intel.com + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + +TSS_RESULT +RPC_NV_DefineOrReleaseSpace_TP(struct host_table_entry *hte, /* in */ + UINT32 cPubInfoSize, /* in */ + BYTE* pPubInfo, /* in */ + TCPA_ENCAUTH encAuth, /* in */ + TPM_AUTH* pAuth) /* in,out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 5); + hte->comm.hdr.u.ordinal = TCSD_ORD_NVDEFINEORRELEASESPACE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &cPubInfoSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 2, pPubInfo, cPubInfoSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_ENCAUTH, 3, &encAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if( pAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 4, pAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + LogDebugFn("getData outputSize"); + + if( pAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, pAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + } + +done: + LogDebugFn("result=%u", result); + return result; +} + +TSS_RESULT +RPC_NV_WriteValue_TP(struct host_table_entry *hte, /* in */ + TSS_NV_INDEX hNVStore, /* in */ + UINT32 offset, /* in */ + UINT32 ulDataLength, /* in */ + BYTE* rgbDataToWrite, /* in */ + TPM_AUTH* privAuth) /* in,out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 6); + hte->comm.hdr.u.ordinal = TCSD_ORD_NVWRITEVALUE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hNVStore, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &offset, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 3, &ulDataLength, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 4, rgbDataToWrite, ulDataLength, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if( privAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 5, privAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + LogDebugFn("getData outputSize"); + + if( privAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, privAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + } + +done: + LogDebugFn("result=%u", result); + return result; +} + +TSS_RESULT +RPC_NV_WriteValueAuth_TP(struct host_table_entry *hte, /* in */ + TSS_NV_INDEX hNVStore, /* in */ + UINT32 offset, /* in */ + UINT32 ulDataLength, /* in */ + BYTE* rgbDataToWrite, /* in */ + TPM_AUTH* NVAuth) /* in,out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 6); + hte->comm.hdr.u.ordinal = TCSD_ORD_NVWRITEVALUEAUTH; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hNVStore, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &offset, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 3, &ulDataLength, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 4, rgbDataToWrite, ulDataLength, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if( NVAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 5, NVAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + LogDebugFn("getData outputSize"); + + if( NVAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, NVAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + } + +done: + LogDebugFn("result=%u", result); + return result; +} + +TSS_RESULT +RPC_NV_ReadValue_TP(struct host_table_entry *hte, /* in */ + TSS_NV_INDEX hNVStore, /* in */ + UINT32 offset, /* in */ + UINT32* pulDataLength, /* in,out */ + TPM_AUTH* privAuth, /* in,out */ + BYTE** rgbDataRead) /* out */ +{ + TSS_RESULT result; + UINT32 i; + + initData(&hte->comm, 5); + hte->comm.hdr.u.ordinal = TCSD_ORD_NVREADVALUE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hNVStore, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &offset, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 3, pulDataLength, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + LogDebugFn("SetData privAuth\n"); + if( privAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 4, privAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + LogDebugFn("Send data.\n"); + result = sendTCSDPacket(hte); + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + LogDebugFn("result=%u", result); + if (result == TSS_SUCCESS) { + i = 0; + LogDebugFn("getData outputSize"); + + if( privAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pulDataLength, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *rgbDataRead = (BYTE *) malloc(*pulDataLength); + if (*rgbDataRead == NULL) { + LogError("malloc of %u bytes failed.", *pulDataLength); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + LogDebugFn("getData rgbDataRead (pulDataLength=%u)", *pulDataLength); + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *rgbDataRead, *pulDataLength, &hte->comm)) { + free(*rgbDataRead); + *rgbDataRead = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + +done: + LogDebugFn("result=%u", result); + return result; +} + +TSS_RESULT +RPC_NV_ReadValueAuth_TP(struct host_table_entry *hte, /* in */ + TSS_NV_INDEX hNVStore, /* in */ + UINT32 offset, /* in */ + UINT32* pulDataLength, /* in,out */ + TPM_AUTH* NVAuth, /* in,out */ + BYTE** rgbDataRead) /* out */ +{ + TSS_RESULT result; + UINT32 i; + + initData(&hte->comm, 5); + hte->comm.hdr.u.ordinal = TCSD_ORD_NVREADVALUEAUTH; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hNVStore, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &offset, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 3, pulDataLength, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if( NVAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 4, NVAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + LogDebugFn("getData outputSize"); + + if( NVAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, NVAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pulDataLength, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *rgbDataRead = (BYTE *) malloc(*pulDataLength); + if (*rgbDataRead == NULL) { + LogError("malloc of %u bytes failed.", *pulDataLength); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + LogDebugFn("getData rgbDataRead (pulDataLength=%u)", *pulDataLength); + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *rgbDataRead, *pulDataLength, &hte->comm)) { + free(*rgbDataRead); + *rgbDataRead = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + +done: + LogDebugFn("result=%u", result); + return result; +} + diff --git a/src/tspi/rpc/tcstp/rpc_oper.c b/src/tspi/rpc/tcstp/rpc_oper.c new file mode 100644 index 0000000..3795aab --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_oper.c @@ -0,0 +1,47 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2007 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_SetOperatorAuth_TP(struct host_table_entry *hte, + TCPA_SECRET *operatorAuth) /* in */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_SETOPERATORAUTH; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_SECRET, 1, operatorAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + diff --git a/src/tspi/rpc/tcstp/rpc_own.c b/src/tspi/rpc/tcstp/rpc_own.c new file mode 100644 index 0000000..7d06ca2 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_own.c @@ -0,0 +1,125 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_TakeOwnership_TP(struct host_table_entry *hte, + UINT16 protocolID, /* in */ + UINT32 encOwnerAuthSize, /* in */ + BYTE * encOwnerAuth, /* in */ + UINT32 encSrkAuthSize, /* in */ + BYTE * encSrkAuth, /* in */ + UINT32 srkInfoSize, /* in */ + BYTE * srkInfo, /* in */ + TPM_AUTH * ownerAuth, /* in, out */ + UINT32 * srkKeySize, + BYTE ** srkKey) +{ + TSS_RESULT result; + + initData(&hte->comm, 9); + hte->comm.hdr.u.ordinal = TCSD_ORD_TAKEOWNERSHIP; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT16, 1, &protocolID, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &encOwnerAuthSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, encOwnerAuth, encOwnerAuthSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 4, &encSrkAuthSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 5, encSrkAuth, encSrkAuthSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 6, &srkInfoSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 7, srkInfo, srkInfoSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_AUTH, 8, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, 1, srkKeySize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *srkKey = (BYTE *) malloc(*srkKeySize); + if (*srkKey == NULL) { + LogError("malloc of %u bytes failed.", *srkKeySize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *srkKey, *srkKeySize, &hte->comm)) { + free(*srkKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} + + +TSS_RESULT +RPC_OwnerClear_TP(struct host_table_entry *hte, + TPM_AUTH * ownerAuth) /* in, out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_OWNERCLEAR; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (setData(TCSD_PACKET_TYPE_AUTH, 1, ownerAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS ){ + if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_pcr_extend.c b/src/tspi/rpc/tcstp/rpc_pcr_extend.c new file mode 100644 index 0000000..3e97ad1 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_pcr_extend.c @@ -0,0 +1,113 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_Extend_TP(struct host_table_entry *hte, + TCPA_PCRINDEX pcrNum, /* in */ + TCPA_DIGEST inDigest, /* in */ + TCPA_PCRVALUE * outDigest /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_EXTEND; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &pcrNum, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_DIGEST, 2, &inDigest, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_DIGEST, 0, outDigest, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_PcrRead_TP(struct host_table_entry *hte, + TCPA_PCRINDEX pcrNum, /* in */ + TCPA_PCRVALUE * outDigest /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_PCRREAD; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &pcrNum, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_DIGEST, 0, outDigest, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +TSS_RESULT +RPC_PcrReset_TP(struct host_table_entry *hte, + UINT32 pcrDataSizeIn, /* in */ + BYTE * pcrDataIn) /* in */ +{ + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_PCRRESET; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &pcrDataSizeIn, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 2, pcrDataIn, pcrDataSizeIn, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_ps.c b/src/tspi/rpc/tcstp/rpc_ps.c new file mode 100644 index 0000000..3a4d704 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_ps.c @@ -0,0 +1,373 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_GetRegisteredKeyByPublicInfo_TP(struct host_table_entry *hte, + TCPA_ALGORITHM_ID algID, /* in */ + UINT32 ulPublicInfoLength, /* in */ + BYTE * rgbPublicInfo, /* in */ + UINT32 * keySize, /* out */ + BYTE ** keyBlob) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 4); + hte->comm.hdr.u.ordinal = TCSD_ORD_GETREGISTEREDKEYBYPUBLICINFO; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &algID, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &ulPublicInfoLength, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, rgbPublicInfo, ulPublicInfoLength, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, keySize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *keyBlob = (BYTE *) malloc(*keySize); + if (*keyBlob == NULL) { + LogError("malloc of %u bytes failed.", *keySize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *keyBlob, *keySize, &hte->comm)) { + free(*keyBlob); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + +done: + return result; +} + +TSS_RESULT +RPC_RegisterKey_TP(struct host_table_entry *hte, + TSS_UUID WrappingKeyUUID, /* in */ + TSS_UUID KeyUUID, /* in */ + UINT32 cKeySize, /* in */ + BYTE * rgbKey, /* in */ + UINT32 cVendorData, /* in */ + BYTE * gbVendorData /* in */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 7); + hte->comm.hdr.u.ordinal = TCSD_ORD_REGISTERKEY; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UUID, 1, &WrappingKeyUUID, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UUID, 2, &KeyUUID, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 3, &cKeySize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 4, rgbKey, cKeySize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 5, &cVendorData, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 6, gbVendorData, cVendorData, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_UnregisterKey_TP(struct host_table_entry *hte, + TSS_UUID KeyUUID /* in */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_UNREGISTERKEY; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UUID, 1, &KeyUUID, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_EnumRegisteredKeys_TP(struct host_table_entry *hte, + TSS_UUID * pKeyUUID, /* in */ + UINT32 * pcKeyHierarchySize, /* out */ + TSS_KM_KEYINFO ** ppKeyHierarchy /* out */ + ) { + TSS_RESULT result; + int i, j; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_ENUMREGISTEREDKEYS; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (pKeyUUID != NULL) { + if (setData(TCSD_PACKET_TYPE_UUID, 1, pKeyUUID, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcKeyHierarchySize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + if (*pcKeyHierarchySize > 0) { + *ppKeyHierarchy = malloc((*pcKeyHierarchySize) * sizeof(TSS_KM_KEYINFO)); + if (*ppKeyHierarchy == NULL) { + LogError("malloc of %zu bytes failed.", (*pcKeyHierarchySize) * + sizeof(TSS_KM_KEYINFO)); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + for (j = 0; (UINT32)j < *pcKeyHierarchySize; j++) { + if (getData(TCSD_PACKET_TYPE_KM_KEYINFO, i++, + &((*ppKeyHierarchy)[j]), 0, &hte->comm)) { + free(*ppKeyHierarchy); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + } else { + *ppKeyHierarchy = NULL; + } + } + +done: + return result; +} + +TSS_RESULT +RPC_EnumRegisteredKeys2_TP(struct host_table_entry *hte, + TSS_UUID * pKeyUUID, /* in */ + UINT32 * pcKeyHierarchySize, /* out */ + TSS_KM_KEYINFO2 ** ppKeyHierarchy /* out */ + ) +{ + TSS_RESULT result; + int i, j; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_ENUMREGISTEREDKEYS2; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (pKeyUUID != NULL) { + if (setData(TCSD_PACKET_TYPE_UUID, 1, pKeyUUID, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcKeyHierarchySize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + if (*pcKeyHierarchySize > 0) { + *ppKeyHierarchy = malloc((*pcKeyHierarchySize) * sizeof(TSS_KM_KEYINFO2)); + if (*ppKeyHierarchy == NULL) { + LogError("malloc of %zu bytes failed.", (*pcKeyHierarchySize) * + sizeof(TSS_KM_KEYINFO2)); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + for (j = 0; (UINT32)j < *pcKeyHierarchySize; j++) { + if (getData(TCSD_PACKET_TYPE_KM_KEYINFO2, i++, + &((*ppKeyHierarchy)[j]), 0, &hte->comm)) { + free(*ppKeyHierarchy); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + } else { + *ppKeyHierarchy = NULL; + } + } + +done: + return result; +} + +TSS_RESULT +RPC_GetRegisteredKey_TP(struct host_table_entry *hte, + TSS_UUID KeyUUID, /* in */ + TSS_KM_KEYINFO ** ppKeyInfo /* out */ + ) { + return TSPERR(TSS_E_NOTIMPL); +} + +TSS_RESULT +RPC_GetRegisteredKeyBlob_TP(struct host_table_entry *hte, + TSS_UUID KeyUUID, /* in */ + UINT32 * pcKeySize, /* out */ + BYTE ** prgbKey /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_GETREGISTEREDKEYBLOB; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UUID, 1, &KeyUUID, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, pcKeySize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *prgbKey = malloc(*pcKeySize); + if (*prgbKey == NULL) { + LogError("malloc of %u bytes failed.", *pcKeySize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *prgbKey, *pcKeySize, &hte->comm)) { + free(*prgbKey); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; + +} + +TSS_RESULT +RPC_LoadKeyByUUID_TP(struct host_table_entry *hte, + TSS_UUID KeyUUID, /* in */ + TCS_LOADKEY_INFO * pLoadKeyInfo, /* in, out */ + TCS_KEY_HANDLE * phKeyTCSI /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_LOADKEYBYUUID; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UUID, 1, &KeyUUID, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (pLoadKeyInfo != NULL) { + if (setData(TCSD_PACKET_TYPE_LOADKEY_INFO, 2, pLoadKeyInfo, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, phKeyTCSI, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + + LogDebugFn("TCS key handle: 0x%x", *phKeyTCSI); + } else if (pLoadKeyInfo && (result == (TCS_E_KM_LOADFAILED | TSS_LAYER_TCS))) { + if (getData(TCSD_PACKET_TYPE_LOADKEY_INFO, 0, pLoadKeyInfo, 0, &hte->comm)) + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + + return result; +} + +void +LoadBlob_LOADKEY_INFO(UINT64 *offset, BYTE *blob, TCS_LOADKEY_INFO *info) +{ + Trspi_LoadBlob_UUID(offset, blob, info->keyUUID); + Trspi_LoadBlob_UUID(offset, blob, info->parentKeyUUID); + Trspi_LoadBlob(offset, TCPA_DIGEST_SIZE, blob, info->paramDigest.digest); + Trspi_LoadBlob_UINT32(offset, info->authData.AuthHandle, blob); + Trspi_LoadBlob(offset, TCPA_NONCE_SIZE, blob, (BYTE *)&info->authData.NonceOdd.nonce); + Trspi_LoadBlob(offset, TCPA_NONCE_SIZE, blob, (BYTE *)&info->authData.NonceEven.nonce); + Trspi_LoadBlob_BOOL(offset, info->authData.fContinueAuthSession, blob); + Trspi_LoadBlob(offset, TCPA_DIGEST_SIZE, blob, (BYTE *)&info->authData.HMAC); +} + +void +UnloadBlob_LOADKEY_INFO(UINT64 *offset, BYTE *blob, TCS_LOADKEY_INFO *info) +{ + Trspi_UnloadBlob_UUID(offset, blob, &info->keyUUID); + Trspi_UnloadBlob_UUID(offset, blob, &info->parentKeyUUID); + Trspi_UnloadBlob(offset, TCPA_DIGEST_SIZE, blob, (BYTE *)&info->paramDigest.digest); + Trspi_UnloadBlob_UINT32(offset, &info->authData.AuthHandle, blob); + Trspi_UnloadBlob(offset, TCPA_NONCE_SIZE, blob, (BYTE *)&info->authData.NonceOdd.nonce); + Trspi_UnloadBlob(offset, TCPA_NONCE_SIZE, blob, (BYTE *)&info->authData.NonceEven.nonce); + Trspi_UnloadBlob_BOOL(offset, &info->authData.fContinueAuthSession, blob); + Trspi_UnloadBlob(offset, TCPA_DIGEST_SIZE, blob, (BYTE *)&info->authData.HMAC); +} + diff --git a/src/tspi/rpc/tcstp/rpc_quote.c b/src/tspi/rpc/tcstp/rpc_quote.c new file mode 100644 index 0000000..7bb1961 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_quote.c @@ -0,0 +1,114 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_Quote_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE keyHandle, /* in */ + TCPA_NONCE *antiReplay, /* in */ + UINT32 pcrDataSizeIn, /* in */ + BYTE * pcrDataIn, /* in */ + TPM_AUTH * privAuth, /* in, out */ + UINT32 * pcrDataSizeOut, /* out */ + BYTE ** pcrDataOut, /* out */ + UINT32 * sigSize, /* out */ + BYTE ** sig) /* out */ +{ + TSS_RESULT result; + int i; + + initData(&hte->comm, 6); + + hte->comm.hdr.u.ordinal = TCSD_ORD_QUOTE; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 2, antiReplay, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 3, &pcrDataSizeIn, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 4, pcrDataIn, pcrDataSizeIn, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (privAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 5, privAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (privAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcrDataSizeOut, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *pcrDataOut = (BYTE *) malloc(*pcrDataSizeOut); + if (*pcrDataOut == NULL) { + LogError("malloc of %u bytes failed.", *pcrDataSizeOut); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *pcrDataOut, *pcrDataSizeOut, &hte->comm)) { + free(*pcrDataOut); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, sigSize, 0, &hte->comm)) { + free(*pcrDataOut); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *sig = (BYTE *) malloc(*sigSize); + if (*sig == NULL) { + LogError("malloc of %u bytes failed.", *sigSize); + free(*pcrDataOut); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *sig, *sigSize, &hte->comm)) { + free(*pcrDataOut); + free(*sig); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_quote2.c b/src/tspi/rpc/tcstp/rpc_quote2.c new file mode 100644 index 0000000..798748f --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_quote2.c @@ -0,0 +1,149 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_Quote2_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE keyHandle, /* in */ + TCPA_NONCE *antiReplay, /* in */ + UINT32 pcrDataSizeIn, /* in */ + BYTE * pcrDataIn, /* in */ + TSS_BOOL addVersion, /* in */ + TPM_AUTH * privAuth, /* in, out */ + UINT32 * pcrDataSizeOut, /* out */ + BYTE ** pcrDataOut, /* out */ + UINT32* versionInfoSize, /* out */ + BYTE** versionInfo, /* out */ + UINT32 * sigSize, /* out */ + BYTE ** sig) /* out */ +{ + TSS_RESULT result; + int i; + + initData(&hte->comm, 7); + + hte->comm.hdr.u.ordinal = TCSD_ORD_QUOTE2; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 2, antiReplay, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 3, &pcrDataSizeIn, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 4, pcrDataIn, pcrDataSizeIn, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_BOOL, 5, &addVersion, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (privAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 6, privAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + /* Takes and sets the output data */ + if (result == TSS_SUCCESS) { + i = 0; + if (privAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcrDataSizeOut, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *pcrDataOut = (BYTE *) malloc(*pcrDataSizeOut); + if (*pcrDataOut == NULL) { + LogError("malloc of %u bytes failed.", *pcrDataSizeOut); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *pcrDataOut, *pcrDataSizeOut, &hte->comm)) { + free(*pcrDataOut); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + /* Retrieves the versionInfo Parameters */ + if (getData(TCSD_PACKET_TYPE_UINT32, i++, versionInfoSize, 0, &hte->comm)) { + free(*pcrDataOut); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (*versionInfoSize >0){ + *versionInfo = (BYTE *) malloc(*versionInfoSize); + if (*versionInfo == NULL) { + LogError("malloc of %u bytes failed.", *versionInfoSize); + free(*pcrDataOut); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *versionInfo, *versionInfoSize, + &hte->comm)) { + free(*pcrDataOut); + free(*versionInfo); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + + if (getData(TCSD_PACKET_TYPE_UINT32, i++, sigSize, 0, &hte->comm)) { + free(*pcrDataOut); + if (addVersion) + free(*versionInfo); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *sig = (BYTE *) malloc(*sigSize); + if (*sig == NULL) { + LogError("malloc of %u bytes failed.", *sigSize); + free(*pcrDataOut); + if (addVersion) + free(*versionInfo); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *sig, *sigSize, &hte->comm)) { + free(*pcrDataOut); + if (addVersion) + free(*versionInfo); + free(*sig); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_random.c b/src/tspi/rpc/tcstp/rpc_random.c new file mode 100644 index 0000000..82edd05 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_random.c @@ -0,0 +1,94 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_GetRandom_TP(struct host_table_entry *hte, + UINT32 bytesRequested, /* in */ + BYTE ** randomBytes) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 2); + hte->comm.hdr.u.ordinal = TCSD_ORD_GETRANDOM; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &bytesRequested, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, &bytesRequested, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *randomBytes = (BYTE *) malloc(bytesRequested); + if (*randomBytes == NULL) { + LogError("malloc of %u bytes failed.", bytesRequested); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *randomBytes, bytesRequested, &hte->comm)) { + free(*randomBytes); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} + +TSS_RESULT +RPC_StirRandom_TP(struct host_table_entry *hte, + UINT32 inDataSize, /* in */ + BYTE * inData) /* in */ +{ + TSS_RESULT result; + + initData(&hte->comm, 3); + hte->comm.hdr.u.ordinal = TCSD_ORD_STIRRANDOM; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &inDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 2, inData, inDataSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_seal.c b/src/tspi/rpc/tcstp/rpc_seal.c new file mode 100644 index 0000000..2bca7e2 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_seal.c @@ -0,0 +1,206 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +common_Seal_TP(UINT32 sealOrdinal, + struct host_table_entry *hte, + TCS_KEY_HANDLE keyHandle, /* in */ + TCPA_ENCAUTH *encAuth, /* in */ + UINT32 pcrInfoSize, /* in */ + BYTE * PcrInfo, /* in */ + UINT32 inDataSize, /* in */ + BYTE * inData, /* in */ + TPM_AUTH * pubAuth, /* in, out */ + UINT32 * SealedDataSize, /* out */ + BYTE ** SealedData /* out */ + ) { + TSS_RESULT result; + int i = 0; + + initData(&hte->comm, 8); + hte->comm.hdr.u.ordinal = sealOrdinal; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &keyHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_ENCAUTH, i++, encAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &pcrInfoSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (pcrInfoSize > 0) { + if (setData(TCSD_PACKET_TYPE_PBYTE, i++, PcrInfo, pcrInfoSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &inDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (inDataSize > 0) { + if (setData(TCSD_PACKET_TYPE_PBYTE, i++, inData, inDataSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + if (setData(TCSD_PACKET_TYPE_AUTH, i, pubAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (hte->comm.hdr.u.result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, pubAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_UINT32, 1, SealedDataSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *SealedData = (BYTE *) malloc(*SealedDataSize); + if (*SealedData == NULL) { + LogError("malloc of %u bytes failed.", *SealedDataSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *SealedData, *SealedDataSize, &hte->comm)) { + free(*SealedData); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} + +TSS_RESULT +RPC_Seal_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE keyHandle, /* in */ + TCPA_ENCAUTH *encAuth, /* in */ + UINT32 pcrInfoSize, /* in */ + BYTE * PcrInfo, /* in */ + UINT32 inDataSize, /* in */ + BYTE * inData, /* in */ + TPM_AUTH * pubAuth, /* in, out */ + UINT32 * SealedDataSize, /* out */ + BYTE ** SealedData /* out */ + ) { + return common_Seal_TP(TCSD_ORD_SEAL, hte, keyHandle, encAuth, pcrInfoSize, PcrInfo, + inDataSize, inData, pubAuth, SealedDataSize, SealedData); +} + +#ifdef TSS_BUILD_SEALX +TSS_RESULT +RPC_Sealx_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE keyHandle, /* in */ + TCPA_ENCAUTH *encAuth, /* in */ + UINT32 pcrInfoSize, /* in */ + BYTE * PcrInfo, /* in */ + UINT32 inDataSize, /* in */ + BYTE * inData, /* in */ + TPM_AUTH * pubAuth, /* in, out */ + UINT32 * SealedDataSize, /* out */ + BYTE ** SealedData /* out */ + ) { + return common_Seal_TP(TCSD_ORD_SEALX, hte, keyHandle, encAuth, pcrInfoSize, PcrInfo, + inDataSize, inData, pubAuth, SealedDataSize, SealedData); +} +#endif + +TSS_RESULT +RPC_Unseal_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE parentHandle, /* in */ + UINT32 SealedDataSize, /* in */ + BYTE * SealedData, /* in */ + TPM_AUTH * parentAuth, /* in, out */ + TPM_AUTH * dataAuth, /* in, out */ + UINT32 * DataSize, /* out */ + BYTE ** Data /* out */ + ) { + TSS_RESULT result; + + initData(&hte->comm, 6); + hte->comm.hdr.u.ordinal = TCSD_ORD_UNSEAL; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &parentHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &SealedDataSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, SealedData, SealedDataSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (parentAuth != NULL) { + if (setData(TCSD_PACKET_TYPE_AUTH, 4, parentAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + if (setData(TCSD_PACKET_TYPE_AUTH, 5, dataAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (parentAuth != NULL) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, parentAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + + if (getData(TCSD_PACKET_TYPE_AUTH, 1, dataAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_UINT32, 2, DataSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *Data = (BYTE *) malloc(*DataSize); + if (*Data == NULL) { + LogError("malloc of %u bytes failed.", *DataSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 3, *Data, *DataSize, &hte->comm)) { + free(*Data); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_selftest.c b/src/tspi/rpc/tcstp/rpc_selftest.c new file mode 100644 index 0000000..3cad950 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_selftest.c @@ -0,0 +1,155 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_SelfTestFull_TP(struct host_table_entry *hte) +{ + TSS_RESULT result; + + initData(&hte->comm, 1); + hte->comm.hdr.u.ordinal = TCSD_ORD_SELFTESTFULL; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + return result; +} + +TSS_RESULT +RPC_CertifySelfTest_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE keyHandle, /* in */ + TCPA_NONCE antiReplay, /* in */ + TPM_AUTH * privAuth, /* in, out */ + UINT32 * sigSize, /* out */ + BYTE ** sig) /* out */ +{ + TSS_RESULT result; + int i; + + initData(&hte->comm, 4); + hte->comm.hdr.u.ordinal = TCSD_ORD_CERTIFYSELFTEST; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 2, &antiReplay, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (privAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 3, privAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (privAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) { + LogDebug("privAuth"); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, sigSize, 0, &hte->comm)) { + LogDebug("sigSize"); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + *sig = (BYTE *) malloc(*sigSize); + if (*sig == NULL) { + LogError("malloc of %u bytes failed.", *sigSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *sig, *sigSize, &hte->comm)) { + LogDebug("sig"); + free(*sig); + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + +done: + return result; +} + +TSS_RESULT +RPC_GetTestResult_TP(struct host_table_entry *hte, + UINT32 * outDataSize, /* out */ + BYTE ** outData) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 1); + hte->comm.hdr.u.ordinal = TCSD_ORD_GETTESTRESULT; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + LogDebug("RPC_GetTestResult_TP"); + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + LogDebug("sendTCSDPacket succeeded"); + if (getData(TCSD_PACKET_TYPE_UINT32, 0, outDataSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *outData = malloc(*outDataSize); + if (*outData == NULL) { + LogError("malloc of %u bytes failed.", *outDataSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *outData, *outDataSize, &hte->comm)) { + free(*outData); + *outData = NULL; + result = TSPERR(TSS_E_INTERNAL_ERROR); + } + } + LogDebug("RPC_GetTestResult_TP exit"); + +done: + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_sign.c b/src/tspi/rpc/tcstp/rpc_sign.c new file mode 100644 index 0000000..dcaf478 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_sign.c @@ -0,0 +1,93 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2006 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_Sign_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE keyHandle, /* in */ + UINT32 areaToSignSize, /* in */ + BYTE * areaToSign, /* in */ + TPM_AUTH * privAuth, /* in, out */ + UINT32 * sigSize, /* out */ + BYTE ** sig /* out */ + ) { + TSS_RESULT result; + int i; + + initData(&hte->comm, 5); + hte->comm.hdr.u.ordinal = TCSD_ORD_SIGN; + LogDebugFn("TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &areaToSignSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 3, areaToSign, areaToSignSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (privAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 4, privAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (privAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, sigSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *sig = (BYTE *) malloc(*sigSize); + if (*sig == NULL) { + LogError("malloc of %u bytes failed.", *sigSize); + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *sig, *sigSize, &hte->comm)) { + result = free_tspi(hte->tspContext, *sig); + if (result == TSS_SUCCESS) + result = TSPERR(TSS_E_INTERNAL_ERROR); + else + free(*sig); + } + } + +done: + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_tick.c b/src/tspi/rpc/tcstp/rpc_tick.c new file mode 100644 index 0000000..6ad0f34 --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_tick.c @@ -0,0 +1,172 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2007 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_ReadCurrentTicks_TP(struct host_table_entry* hte, + UINT32* pulCurrentTime, /* out */ + BYTE** prgbCurrentTime) /* out */ +{ + TSS_RESULT result; + + initData(&hte->comm, 1); + hte->comm.hdr.u.ordinal = TCSD_ORD_READCURRENTTICKS; + LogDebugFn("IN: TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (getData(TCSD_PACKET_TYPE_UINT32, 0, pulCurrentTime, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *prgbCurrentTime = malloc(*pulCurrentTime); + if (*prgbCurrentTime == NULL) { + *pulCurrentTime = 0; + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *prgbCurrentTime, *pulCurrentTime, + &hte->comm)) { + free(*prgbCurrentTime); + *prgbCurrentTime = NULL; + *pulCurrentTime = 0; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } +done: + return result; +} + +TSS_RESULT +RPC_TickStampBlob_TP(struct host_table_entry* hte, + TCS_KEY_HANDLE hKey, /* in */ + TPM_NONCE* antiReplay, /* in */ + TPM_DIGEST* digestToStamp, /* in */ + TPM_AUTH* privAuth, /* in, out */ + UINT32* pulSignatureLength, /* out */ + BYTE** prgbSignature, /* out */ + UINT32* pulTickCountLength, /* out */ + BYTE** prgbTickCount) /* out */ + +{ + TSS_RESULT result; + UINT32 i; + + initData(&hte->comm, 5); + hte->comm.hdr.u.ordinal = TCSD_ORD_TICKSTAMPBLOB; + LogDebugFn("IN: TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 2, antiReplay, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_DIGEST, 3, digestToStamp, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (privAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 4, privAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (privAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pulSignatureLength, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *prgbSignature = malloc(*pulSignatureLength); + if (*prgbSignature == NULL) { + *pulSignatureLength = 0; + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbSignature, *pulSignatureLength, + &hte->comm)) { + free(*prgbSignature); + *prgbSignature = NULL; + *pulSignatureLength = 0; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pulTickCountLength, 0, &hte->comm)) { + free(*prgbSignature); + *prgbSignature = NULL; + *pulSignatureLength = 0; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *prgbTickCount = malloc(*pulTickCountLength); + if (*prgbTickCount == NULL) { + free(*prgbSignature); + *prgbSignature = NULL; + *pulSignatureLength = 0; + *pulTickCountLength = 0; + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbTickCount, *pulTickCountLength, + &hte->comm)) { + free(*prgbSignature); + *prgbSignature = NULL; + *pulSignatureLength = 0; + free(*prgbTickCount); + *prgbTickCount = NULL; + *pulTickCountLength = 0; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } +done: + return result; +} diff --git a/src/tspi/rpc/tcstp/rpc_transport.c b/src/tspi/rpc/tcstp/rpc_transport.c new file mode 100644 index 0000000..91102cc --- /dev/null +++ b/src/tspi/rpc/tcstp/rpc_transport.c @@ -0,0 +1,368 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2004-2007 + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "trousers/tss.h" +#include "trousers/trousers.h" +#include "trousers_types.h" +#include "spi_utils.h" +#include "capabilities.h" +#include "tsplog.h" +#include "hosttable.h" +#include "tcsd_wrap.h" +#include "obj.h" +#include "rpc_tcstp_tsp.h" + + +TSS_RESULT +RPC_EstablishTransport_TP(struct host_table_entry *hte, + UINT32 ulTransControlFlags, + TCS_KEY_HANDLE hEncKey, + UINT32 ulTransSessionInfoSize, + BYTE* rgbTransSessionInfo, + UINT32 ulSecretSize, + BYTE* rgbSecret, + TPM_AUTH* pEncKeyAuth, /* in, out */ + TPM_MODIFIER_INDICATOR* pbLocality, + TCS_HANDLE* hTransSession, + UINT32* ulCurrentTicksSize, + BYTE** prgbCurrentTicks, + TPM_NONCE* pTransNonce) +{ + TSS_RESULT result; + UINT32 i; + + initData(&hte->comm, 8); + hte->comm.hdr.u.ordinal = TCSD_ORD_ESTABLISHTRANSPORT; + LogDebugFn("IN: TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &ulTransControlFlags, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 2, &hEncKey, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 3, &ulTransSessionInfoSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 4, rgbTransSessionInfo, ulTransSessionInfoSize, + &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 5, &ulSecretSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, 6, rgbSecret, ulSecretSize, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (pEncKeyAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 7, pEncKeyAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (pEncKeyAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, pEncKeyAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pbLocality, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, hTransSession, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, ulCurrentTicksSize, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + + *prgbCurrentTicks = malloc(*ulCurrentTicksSize); + if (*prgbCurrentTicks == NULL) { + *ulCurrentTicksSize = 0; + result = TSPERR(TSS_E_OUTOFMEMORY); + goto done; + } + + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbCurrentTicks, *ulCurrentTicksSize, + &hte->comm)) { + free(*prgbCurrentTicks); + *prgbCurrentTicks = NULL; + *ulCurrentTicksSize = 0; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + if (getData(TCSD_PACKET_TYPE_NONCE, i++, pTransNonce, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto done; + } + } +done: + return result; +} + + +TSS_RESULT +RPC_ExecuteTransport_TP(struct host_table_entry *hte, + TPM_COMMAND_CODE unWrappedCommandOrdinal, + UINT32 ulWrappedCmdParamInSize, + BYTE* rgbWrappedCmdParamIn, + UINT32* pulHandleListSize, /* in, out */ + TCS_HANDLE** rghHandles, /* in, out */ + TPM_AUTH* pWrappedCmdAuth1, /* in, out */ + TPM_AUTH* pWrappedCmdAuth2, /* in, out */ + TPM_AUTH* pTransAuth, /* in, out */ + UINT64* punCurrentTicks, + TPM_MODIFIER_INDICATOR* pbLocality, + TPM_RESULT* pulWrappedCmdReturnCode, + UINT32* ulWrappedCmdParamOutSize, + BYTE** rgbWrappedCmdParamOut) +{ + TSS_RESULT result; + TPM_AUTH null_auth; + UINT32 i = 0; + + memset(&null_auth, 0, sizeof(TPM_AUTH)); + + initData(&hte->comm, 9); + hte->comm.hdr.u.ordinal = TCSD_ORD_EXECUTETRANSPORT; + LogDebugFn("IN: TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &unWrappedCommandOrdinal, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, i++, &ulWrappedCmdParamInSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_PBYTE, i++, rgbWrappedCmdParamIn, ulWrappedCmdParamInSize, + &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, i++, pulHandleListSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (*pulHandleListSize) { + if (setData(TCSD_PACKET_TYPE_PBYTE, i++, *rghHandles, + *pulHandleListSize * sizeof(UINT32), &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (pWrappedCmdAuth1) { + if (setData(TCSD_PACKET_TYPE_AUTH, i++, pWrappedCmdAuth1, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + if (setData(TCSD_PACKET_TYPE_AUTH, i++, &null_auth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (pWrappedCmdAuth2) { + if (setData(TCSD_PACKET_TYPE_AUTH, i++, pWrappedCmdAuth2, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + if (setData(TCSD_PACKET_TYPE_AUTH, i++, &null_auth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (setData(TCSD_PACKET_TYPE_AUTH, i++, pTransAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + i = 0; + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pulHandleListSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + if (*pulHandleListSize) { + *rghHandles = malloc(*pulHandleListSize * sizeof(UINT32)); + if (*rghHandles == NULL) { + *pulHandleListSize = 0; + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *rghHandles, + *pulHandleListSize * sizeof(UINT32), &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto error; + } + } + if (pWrappedCmdAuth1) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, pWrappedCmdAuth1, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto error; + } + } else { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, &null_auth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto error; + } + } + if (pWrappedCmdAuth2) { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, pWrappedCmdAuth2, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto error; + } + } else { + if (getData(TCSD_PACKET_TYPE_AUTH, i++, &null_auth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto error; + } + } + if (getData(TCSD_PACKET_TYPE_AUTH, i++, pTransAuth, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto error; + } + if (getData(TCSD_PACKET_TYPE_UINT64, i++, punCurrentTicks, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto error; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pbLocality, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto error; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, pulWrappedCmdReturnCode, 0, &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto error; + } + if (getData(TCSD_PACKET_TYPE_UINT32, i++, ulWrappedCmdParamOutSize, 0, + &hte->comm)) { + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto error; + } + if (*ulWrappedCmdParamOutSize) { + *rgbWrappedCmdParamOut = malloc(*ulWrappedCmdParamOutSize); + if (*rgbWrappedCmdParamOut == NULL) { + *ulWrappedCmdParamOutSize = 0; + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto error; + } + if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *rgbWrappedCmdParamOut, + *ulWrappedCmdParamOutSize, &hte->comm)) { + free(*rgbWrappedCmdParamOut); + result = TSPERR(TSS_E_INTERNAL_ERROR); + goto error; + } + } else + *rgbWrappedCmdParamOut = NULL; + } + + return result; +error: + if (*pulHandleListSize) { + free(*rghHandles); + *rghHandles = NULL; + } + return result; +} + +TSS_RESULT +RPC_ReleaseTransportSigned_TP(struct host_table_entry *hte, + TCS_KEY_HANDLE hSignatureKey, + TPM_NONCE* AntiReplayNonce, + TPM_AUTH* pKeyAuth, /* in, out */ + TPM_AUTH* pTransAuth, /* in, out */ + TPM_MODIFIER_INDICATOR* pbLocality, + UINT32* pulCurrentTicksSize, + BYTE** prgbCurrentTicks, + UINT32* pulSignatureSize, + BYTE** prgbSignature) +{ + TSS_RESULT result; + TPM_AUTH null_auth; + + memset(&null_auth, 0, sizeof(TPM_AUTH)); + + initData(&hte->comm, 5); + hte->comm.hdr.u.ordinal = TCSD_ORD_RELEASETRANSPORTSIGNED; + LogDebugFn("IN: TCS Context: 0x%x", hte->tcsContext); + + if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hSignatureKey, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (setData(TCSD_PACKET_TYPE_NONCE, 2, AntiReplayNonce, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (pKeyAuth) { + if (setData(TCSD_PACKET_TYPE_AUTH, 3, pKeyAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + if (setData(TCSD_PACKET_TYPE_AUTH, 3, &null_auth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (setData(TCSD_PACKET_TYPE_AUTH, 4, pTransAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + result = sendTCSDPacket(hte); + + if (result == TSS_SUCCESS) + result = hte->comm.hdr.u.result; + + if (result == TSS_SUCCESS) { + if (pKeyAuth) { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, pKeyAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } else { + if (getData(TCSD_PACKET_TYPE_AUTH, 0, &null_auth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_AUTH, 1, pTransAuth, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_UINT32, 2, pbLocality, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + if (getData(TCSD_PACKET_TYPE_UINT32, 3, pulCurrentTicksSize, 0, &hte->comm)) + return TSPERR(TSS_E_INTERNAL_ERROR); + + *prgbCurrentTicks = malloc(*pulCurrentTicksSize); + if (*prgbCurrentTicks == NULL) { + *pulCurrentTicksSize = 0; + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 4, *prgbCurrentTicks, *pulCurrentTicksSize, + &hte->comm)) { + free(*prgbCurrentTicks); + *prgbCurrentTicks = NULL; + *pulCurrentTicksSize = 0; + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_UINT32, 5, pulSignatureSize, 0, &hte->comm)) { + free(*prgbCurrentTicks); + *prgbCurrentTicks = NULL; + *pulCurrentTicksSize = 0; + return TSPERR(TSS_E_INTERNAL_ERROR); + } + + *prgbSignature = malloc(*pulSignatureSize); + if (*prgbSignature == NULL) { + free(*prgbCurrentTicks); + *prgbCurrentTicks = NULL; + *pulCurrentTicksSize = 0; + *pulSignatureSize = 0; + return TSPERR(TSS_E_INTERNAL_ERROR); + } + if (getData(TCSD_PACKET_TYPE_PBYTE, 6, *prgbSignature, *pulSignatureSize, + &hte->comm)) { + free(*prgbCurrentTicks); + *prgbCurrentTicks = NULL; + *pulCurrentTicksSize = 0; + free(*prgbSignature); + *prgbSignature = NULL; + *pulSignatureSize = 0; + return TSPERR(TSS_E_INTERNAL_ERROR); + } + } + + return result; +} |