// Thread for receving reconf void* reconf_fun(void* arg) { int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); struct sockaddr_un addr; addr.sun_family = AF_UNIX; strcpy(addr.sun_path, "reconf_socket"); unlink("reconf_socket"); if(bind(sockfd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { print_error("Failed to create unix socket, %s %d\n", strerror(errno), errno); } print_success("Created socket"); int sock; if (listen(sockfd, 5) < 0) print_error("Failed to listen on unix socket\n"); if ((sock = accept(sockfd, NULL, NULL)) < 0) print_error("Failed to accept unix socket\n"); else print_success("Unix socket accepted"); char buf[1] = {' '}; while(1) { if(read(sock, buf, sizeof(buf)) > 0) { if(buf[0] == 'r' && mode == RING) { //print_info("I got reconf!!\n"); mode = RECONF; send_reconf_msg(); while(1) { //print_info("Waiting for reconf to come back\n"); unsigned char buf[MAX_DATA]; unsigned last_addr_len = sizeof(last_addr); int len = recvfrom(sock_last, buf, MAX_DATA, 0, (struct sockaddr*)&last_addr, &last_addr_len); if(len < 1) continue; union msg received_msg; int msg_type = unpack_msg(buf, &received_msg); //print_info("Got message %d\n", msg_type); if(msg_type == RECONF_MSG) break; } print_success("Now you can reconfigure network!"); } else if(buf[0] == 'i' && mode == RECONF) { send_init_msg(); mode = RING; } } else sleep(1); } return NULL; }
TSS_RESULT registerkey(int i) { TSS_RESULT result; char *function = "Tspi_Context_RegisterKey"; printf("%s: key %d\n", __FUNCTION__, i); result = Tspi_Context_RegisterKey( hContext, hKey[i].handle, TSS_PS_TYPE_SYSTEM, hKey[i].uuid, TSS_PS_TYPE_SYSTEM, SRK_UUID ); if (result != TSS_SUCCESS) { if( !(checkNonAPI(result)) ) { print_error( function, result ); return result; } else { print_error_nonapi( function, result ); return result; } } else { hKey[i].registered = 1; print_success( function, result ); return 0; } }
main_v1_1(void){ char *nameOfFunction = "Tspi_GetAttribData07"; TSS_HKEY hKey; TSS_HCONTEXT hContext; TSS_RESULT result; BYTE* BLOB; UINT32 BlobLength; print_begin_test(nameOfFunction); //Call GetAttribData result = Tspi_GetAttribData(hKey, TSS_TSPATTRIB_KEY_BLOB, TSS_TSPATTRIB_KEYBLOB_BLOB, &BlobLength, &BLOB); if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) { if(!checkNonAPI(result)){ print_error(nameOfFunction, result); print_end_test(nameOfFunction); exit(result); } else{ print_error_nonapi(nameOfFunction, result); print_end_test(nameOfFunction); exit(result); } } else{ print_success(nameOfFunction, result); print_end_test(nameOfFunction); exit(0); } }
int main_v1_2(char version) { char *function = "Tspi_TPM_PcrRead-trans03"; BYTE *rgbPcrValue; UINT32 ulPcrValueLength; TSS_HCONTEXT hContext; TSS_HTPM hTPM; TSS_RESULT result; TSS_HKEY hSRK, hWrappingKey; print_begin_test( function ); result = connect_load_all(&hContext, &hSRK, &hTPM); if ( result != TSS_SUCCESS ) { print_error( "connect_load_all", result ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } result = Testsuite_Transport_Init(hContext, hSRK, hTPM, FALSE, TRUE, &hWrappingKey, NULL); if (result != TSS_SUCCESS) { print_error("Testsuite_Transport_Init", result); Tspi_Context_Close(hContext); exit(result); } result = Tspi_TPM_PcrRead( hTPM, 8, &ulPcrValueLength, &rgbPcrValue ); if (result != TSS_SUCCESS) { print_error("Tspi_TPM_PcrRead", result); Tspi_Context_Close(hContext); exit(result); } result = Testsuite_Transport_Final(hContext, 0); if ( result != TSS_SUCCESS ) { if( !(checkNonAPI(result)) ) { print_error( function, result ); } else { print_error_nonapi( function, result ); } } else { print_success( function, result ); } print_end_test( function ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); }
int main_v1_1( void ) { char *function = "Tspi_TPM_StirRandom02"; BYTE entropy; TSS_HCONTEXT hContext; TSS_HTPM whTPM = -1; TSS_RESULT result; UINT32 exitCode = 0; print_begin_test( function ); // seed entropy with time srand( time(0) ); // Create Context result = Tspi_Context_Create( &hContext ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_Create", result ); exit( result ); } // Connect to Context result = Tspi_Context_Connect( hContext, get_server(GLOBALSERVER) ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_Connect", result ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } entropy = ( rand() % 100 ); //Get random number result = Tspi_TPM_StirRandom( whTPM, 16, &entropy ); if ( TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE ) { if( !(checkNonAPI(result)) ) { print_error( function, result ); } else { print_error_nonapi( function, result ); } exitCode = result; } else { print_success( function, result ); } print_end_test( function ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( exitCode ); }
main_v1_1(void){ char *nameOfFunction = "Tspi_GetAttribData09"; TSS_HCONTEXT hContext; TSS_RESULT result; TSS_HKEY hSRK; BYTE* BLOB; UINT32 BlobLength; print_begin_test(nameOfFunction); //Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create ", result); exit(result); } //Connect Context result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER)); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect", result); Tspi_Context_Close(hContext); exit(result); } //Load Key by UUID for SRK result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM, SRK_UUID, &hSRK); if (result != TSS_SUCCESS) { print_error("Tspi_Context_LoadKeyByUUID", result); Tspi_Context_Close(hContext); exit(result); } //Call GetAttribData result = Tspi_GetAttribData(hSRK, TSS_TSPATTRIB_KEY_BLOB, TSS_TSPATTRIB_KEYBLOB_PUBLIC_KEY, &BlobLength, &BLOB); if (TSS_ERROR_CODE(result) != TSS_E_BAD_PARAMETER) { if(!checkNonAPI(result)){ print_error(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } else{ print_error_nonapi(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } } else{ print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(0); } }
main_v1_2(char version){ char *nameOfFunction = "Tspi_TPM_OwnerGetSRKPubKey01"; TSS_RESULT result; TSS_HCONTEXT hContext; TSS_HTPM hTPM; TSS_HKEY hSRK; TSS_HPOLICY hPolicy; UINT32 pulPubKeyLength; BYTE *prgbPubKey; print_begin_test(nameOfFunction); //Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create", result); exit(result); } //Connect Context result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER)); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect", result); exit(result); } //Get TPM Object result = Tspi_Context_GetTpmObject(hContext, &hTPM); if (result != TSS_SUCCESS) { print_error("Tspi_Context_GetTpmObject", result); exit(result); } result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hPolicy ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_GetPolicyObject", result ); return result; } result = Tspi_Policy_SetSecret( hPolicy, TESTSUITE_OWNER_SECRET_MODE, TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Policy_SetSecret", result ); return result; } //Get SRK Public Key result = Tspi_TPM_OwnerGetSRKPubKey(hTPM, &pulPubKeyLength, &prgbPubKey); if (result != TSS_SUCCESS) { print_error(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(result); } else { print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(0); } }
int main_v1_2(char version) { char *function = "Tspi_TPM_SetStatus-trans01"; TSS_HCONTEXT hContext; TSS_HTPM hTPM; TSS_RESULT result; TSS_HKEY hSRK, hSigningKey, hWrappingKey; print_begin_test( function ); result = connect_load_all(&hContext, &hSRK, &hTPM); if ( result != TSS_SUCCESS ) { print_error( "connect_load_all", (result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey, &hSigningKey); if (result != TSS_SUCCESS) { print_error("Testsuite_Transport_Init", result); Tspi_Context_Close(hContext); exit(result); } //Get random number result = Tspi_TPM_SetStatus( hTPM, TSS_TPMSTATUS_SETOWNERINSTALL, TRUE ); if (result != TSS_SUCCESS) { print_error("Tspi_TPM_SetStatus", result); Tspi_Context_Close(hContext); exit(result); } result = Testsuite_Transport_Final(hContext, hSigningKey); if ( result != TSS_SUCCESS ) { if( !(checkNonAPI(result)) ) { print_error( function, result ); } else { print_error_nonapi( function, result ); } } else { print_success( function, result ); } print_end_test( function ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); }
main_v1_2(char version){ char *nameOfFunction = "Tspi_TPM_OwnerGetSRKPubKey02"; TSS_RESULT result; TSS_HCONTEXT hContext; TSS_HKEY hSRK; TSS_HPOLICY hPolicy; UINT32 pulPubKeyLength; BYTE *prgbPubKey; print_begin_test(nameOfFunction); //Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create", result); exit(result); } //Connect Context result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER)); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect", result); exit(result); } //Get SRK Public Key result = Tspi_TPM_OwnerGetSRKPubKey(0xffffffff, &pulPubKeyLength, &prgbPubKey); if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) { if(!checkNonAPI(result)){ print_error(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(result); } else { print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(result);} } else { print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(0); } }
int main_v1_2(char version) { char *nameOfFunction = "Tspi_TPM_SelfTestFull-trans03"; TSS_HCONTEXT hContext; TSS_RESULT result; TSS_HTPM hTPM; TSS_HKEY hSRK, hWrappingKey; print_begin_test(nameOfFunction); result = connect_load_all(&hContext, &hSRK, &hTPM); if ( result != TSS_SUCCESS ) { print_error( "connect_load_all", (result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey, NULL); if (result != TSS_SUCCESS) { print_error("Testsuite_Transport_Init", result); Tspi_Context_Close(hContext); exit(result); } //Call self test full result = Tspi_TPM_SelfTestFull(hTPM); if (result != TSS_SUCCESS) { print_error("Tspi_TPM_SelfTestFull", result); Tspi_Context_Close(hContext); exit(result); } result = Testsuite_Transport_Final(hContext, 0); if (result != TSS_SUCCESS) { if(!checkNonAPI(result)){ print_error(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(result); } else{ print_error_nonapi(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(result); } } else{ print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(0); } }
// Loop for communication with last sensor void last_loop() { print_info("Last loop"); while(1) { if(mode == RECONF) { sleep(1); continue; } print_info("Waiting for data from last..."); unsigned char buf[MAX_DATA]; unsigned last_addr_len = sizeof(last_addr); int len = recvfrom(sock_last, buf, MAX_DATA, 0, (struct sockaddr*)&last_addr, &last_addr_len); if(len < 0) { mode = DOUBLE_LIST; resolving_error = 1; print_warning("Didn't receive data message from last sensor"); print_success("Mode changed to double-list"); if(send_error_msg(FIRST) < 0 || receive_ack_and_finit(FIRST) < 0) { close_first = 1; } if(send_error_msg(LAST) < 0 || receive_ack_and_finit(LAST) < 0) { resolving_error = 0; return; } resolving_error = 0; } else { union msg received_msg; int msg_type = unpack_msg(buf, &received_msg); switch(msg_type) { case INIT_MSG: take_init_msg(received_msg.init); break; case DATA_MSG: take_data_msg(received_msg.data); break; default: print_warning("Received unknown bytes"); } cleanup_msg(&received_msg); } usleep(SERVER_TIMEOUT*1000); if(mode == DOUBLE_LIST) { print_info("Sending data to last sensor..."); send_data_msg(LAST); } } }
int main_v1_2( char version ) { char * function = "Tspi_TPM_Delegate_UpdateVerificationCount03"; TSS_HCONTEXT hContext; TSS_HKEY hSRK; TSS_HTPM hTPM; TSS_HPOLICY hTPMPolicy; TSS_RESULT result; print_begin_test( function ); result = connect_load_all(&hContext, &hSRK, &hTPM); if ( result != TSS_SUCCESS ) { print_error( "connect_load_all", result ); goto done; } result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_GetPolicyObject", result ); goto done; } result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE, TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Policy_SetSecret", result ); goto done; } result = Tspi_TPM_Delegate_UpdateVerificationCount(hTPM, -1); if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) { print_error( function, result ); result = 1; goto done; } else { print_success( function, result ); result = 0; } done: Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); print_end_test( function ); exit( result ); }
main_v1_1(void){ char *nameOfFunction = "Tspi_TPM_SelfTestFull02"; TSS_HCONTEXT hContext; TSS_RESULT result; TSS_HTPM hTPM; print_begin_test(nameOfFunction); //Create Result result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create ", result); exit(result); } //Connect Result result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER)); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect ", result); Tspi_Context_Close(hContext); exit(result); } //Get TPM Object result = Tspi_Context_GetTpmObject(hContext, &hTPM); if (result != TSS_SUCCESS) { print_error("Tspi_Context_GetTpmObject ", result); Tspi_Context_Close(hContext); exit(result); } //Self Test result = Tspi_TPM_SelfTestFull(-1); if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) { if(!checkNonAPI(result)){ print_error(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } else{ print_error_nonapi(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } } else{ print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(0); } }
int main_v1_1(void){ char *nameOfFunction = "Tspi_Context_CreateObject02"; TSS_HCONTEXT hContext; TSS_HKEY hSignatureKey; TSS_RESULT result; print_begin_test(nameOfFunction); //Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create ", result); exit(result); } //Connect Context result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER)); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect ", result); Tspi_Context_Close(hContext); exit(result); } //Create Object result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH, TSS_KEY_SIZE_2048 | TSS_KEY_TYPE_SIGNING | TSS_KEY_MIGRATABLE, &hSignatureKey); if (TSS_ERROR_CODE(result) != TSS_E_INVALID_OBJECT_INITFLAG){ if(!checkNonAPI(result)){ print_error(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_CloseObject(hContext, hSignatureKey); Tspi_Context_Close(hContext); exit(result); } else{ print_error_nonapi(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_CloseObject(hContext, hSignatureKey); Tspi_Context_Close(hContext); exit(result); } } else{ print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_CloseObject(hContext, hSignatureKey); Tspi_Context_Close(hContext); exit(0); } }
/** * @brief Przyjmij pakiet z danymi i wyświetl je. * @param received_msg Struktura z danymi * @return 0 jeśli się udało, lub błąd, gdy inna liczba. */ static int take_data_msg(struct data_msg received_msg) { int data_count = received_msg.count; print_success("Received %d measurements:", data_count); int i; for(i = 0; i < data_count; ++i) { print_info("Sensor: %d Data: %d", received_msg.data[i].id, received_msg.data[i].data); } return 0; }
main_v1_2(char version) { char *nameOfFunction = "Tspi_TPM_ReadCounter03"; TSS_HCONTEXT hContext; TSS_HTPM hTPM; TSS_RESULT result; print_begin_test(nameOfFunction); //Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create ", result); exit(result); } //Connect Context result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER)); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect", result); exit(result); } //GetTPM Object result = Tspi_Context_GetTpmObject(hContext, &hTPM); if (result != TSS_SUCCESS) { print_error("Tspi_Context_GetTPMObject", result); exit(result); } // Read Counter result = Tspi_TPM_ReadCounter(hTPM, NULL); if (TSS_ERROR_CODE(result) != TSS_E_BAD_PARAMETER) { if(!checkNonAPI(result)){ print_error(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } else{ print_error_nonapi(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } } else{ print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(0); } }
int main_v1_1( void ) { char *function = "Tspi_Context_FreeMemory02"; BYTE random; TSS_HCONTEXT hContext; TSS_HCONTEXT whContext = -1; TSS_RESULT result; UINT32 exitCode = 0; print_begin_test( function ); // Create Context result = Tspi_Context_Create( &hContext ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_Create", result ); exit( result ); } // Connect to Context result = Tspi_Context_Connect( hContext, get_server(GLOBALSERVER) ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_Connect", result ); Tspi_Context_Close( hContext ); exit( result ); } // Free selected memory result = Tspi_Context_FreeMemory( whContext, &random ); if ( TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE ) { if( !(checkNonAPI(result)) ) { print_error( function, result ); exitCode = result; } else { print_error_nonapi( function, result ); exitCode = result; } } else { print_success( function, result ); } print_end_test( function ); Tspi_Context_Close( hContext ); exit( exitCode ); }
int main_v1_1(void) { char *function = "Tspi_Hash_GetHashValue04"; TSS_HCONTEXT hContext; TSS_HHASH hHash; UINT32 ulHashValueLength, exitCode = 0; BYTE *rgbHashValue, hashBuf[20]; TSS_RESULT result; print_begin_test(function); // Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create", result); exit(result); } // Connect to Context result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER)); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect", result); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH, TSS_HASH_SHA1, &hHash); if (result != TSS_SUCCESS) { print_error("Tspi_Context_CreateObject (hash)", result); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } result = Tspi_Hash_GetHashValue(hHash, &ulHashValueLength, &rgbHashValue); if (TSS_ERROR_CODE(result) != TSS_E_HASH_NO_DATA) { if (!(checkNonAPI(result))) { print_error(function, result); } else { print_error_nonapi(function, result); } exitCode = result; } else { print_success(function, result); } print_end_test(function); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(exitCode); }
int main_v1_1(void){ TSS_HCONTEXT hContext; TSS_RESULT result; TSS_HKEY hSRK, hKey2; TSS_UUID uuid0, uuid1, uuid2, SRK_UUID = TSS_UUID_SRK; TSS_UUID *uuids[] = { &uuid0, &uuid1, &uuid2, NULL }; print_begin_test(nameOfFunction); memset(&uuid0, 0x5a, sizeof(TSS_UUID)); memset(&uuid1, 0x5b, sizeof(TSS_UUID)); memset(&uuid2, 0x5c, sizeof(TSS_UUID)); //Create Result result = connect_load_srk(&hContext, &hSRK); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create ", result); exit(result); } if ((result = store_keys(hContext, hSRK, &SRK_UUID, uuids))) { Tspi_Context_Close(hContext); exit(result); } //Load Key By UUID result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM, uuid2, &hKey2); if (result != TSS_SUCCESS) { if(!checkNonAPI(result)){ print_error(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(result); } else{ print_error_nonapi(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(result); } } else{ print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(0); } }
main_v1_1(void){ char *nameOfFunction = "Tspi_TPM_GetEvents03"; TSS_HCONTEXT hContext; TSS_RESULT result; TSS_HTPM hTPM; TSS_PCR_EVENT* prgPcrEvents; print_begin_test(nameOfFunction); //Create Result result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create ", result); exit(result); } //Connect Result result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER)); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect ", result); Tspi_Context_Close(hContext); exit(result); } //Get TPM Object result = Tspi_Context_GetTpmObject(hContext, &hTPM); if (result != TSS_SUCCESS) { print_error("Tspi_Context_GetTpmObject ", result); Tspi_Context_Close(hContext); exit(result); } //Get Events result = Tspi_TPM_GetEvents(-1, -1, -1, &hContext, &prgPcrEvents); if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) { if(!checkNonAPI(result)){ print_error(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(result); } else{ print_error_nonapi(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(result); } } else{ print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(0); } }
static int check_output_line(char *line) { if (strtok(line, " \n") == NULL) return -1; if (tolower(turn[0]) == 'b') { if (strtok(NULL, " \n") == NULL) return -1; } char *move = strtok(NULL, " \n"); if (move == NULL) return -1; if (best_move_count > 0) { for (unsigned i = 0; i < best_move_count; ++i) { if (strcmp(move, best_moves[i]) == 0) { print_success(move); return 0; } } print_fail(move); } else if (avoid_move_count > 0) { for (unsigned i = 0; i < avoid_move_count; ++i) { if (strcmp(move, avoid_moves[i]) == 0) { print_fail(move); return 0; } } print_success(move); } else { print_success(move); } return 0; }
// Receive ack message int receive_ack_and_finit(int num) { int sockfd = sock_first; struct sockaddr_in addr = first_addr; char* nums = "first"; if(num == LAST) { sockfd = sock_last; addr = last_addr; nums = "last"; } if(setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &error_timeout, sizeof(struct timeval)) < 0) { print_error("Failed to set error timeout"); } else { print_success("Error timeout set"); } unsigned char buf[MAX_DATA]; unsigned addr_len = sizeof(addr); print_info("Waiting for ack from %d...", num); int len = recvfrom(sockfd, buf, MAX_DATA, 0, (struct sockaddr*)&addr, &addr_len); union msg received_msg; int msg_type = unpack_msg(buf, &received_msg); if(len < 0 || msg_type != ACK_MSG) { print_error("Failed to receive ack msg from %s sensor", nums); print_info("Received %d type instead", msg_type); print_success("Closing socket"); close(sockfd); return -1; } print_success("Received ack msg from %d", num); len = recvfrom(sockfd, buf, MAX_DATA, 0, (struct sockaddr*)&addr, &addr_len); msg_type = unpack_msg(buf, &received_msg); if(len < 0 || msg_type != FINIT_MSG) { print_error("Failed to receive finit msg from %s sensor", nums); print_info("Received %d type instead", msg_type); print_success("Closing socket"); close(sockfd); return -1; } print_success("Received finit msg from %d", num); if(setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)) < 0) { print_error("Failed to return to normal timeout"); } else { print_success("Returned to normal timeout"); } return 0; }
int main_v1_1(void){ char *nameOfFunction = "Tspi_Context_Close03"; TSS_HCONTEXT hContext; TSS_RESULT result; print_begin_test(nameOfFunction); //Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create", result); exit(result); } //Connect Context result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER)); if (result != TSS_SUCCESS){ print_error("Tspi_Context_Connect", result); Tspi_Context_Close(hContext); exit(result); } //Close Context result = Tspi_Context_Close(-1); if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) { if(!checkNonAPI(result)){ print_error(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(result); } else{ print_error_nonapi(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(result); } } else{ print_success(nameOfFunction, result); print_end_test(nameOfFunction); exit(0); } }
int main_v1_1(void) { char *function = "Tspi_Hash_UpdateHashValue02"; TSS_HCONTEXT hContext; TSS_HHASH whHash = -1; TSS_RESULT result; UINT32 exitCode = 0; print_begin_test(function); // Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create", result); exit(result); } // Connect to Context result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER)); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect", result); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } result = Tspi_Hash_UpdateHashValue(whHash, 24, "Je pense, danc je suis."); if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) { if (!(checkNonAPI(result))) { print_error(function, result); } else { print_error_nonapi(function, result); } exitCode = result; } else { print_success(function, result); } print_end_test(function); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(exitCode); }
// Loop for communication with first sensor void* first_loop(void* arg) { print_success("Loop thread started"); send_init_msg(); while(1) { if(close_first) return NULL; if(mode == RECONF) { sleep(1); continue; } if(resolving_error) { usleep(SERVER_TIMEOUT*1000); continue; } send_data_msg(FIRST); if(mode == DOUBLE_LIST) { print_info("Waiting for data from first..."); unsigned char buf[MAX_DATA]; unsigned first_addr_len = sizeof(first_addr); int len = recvfrom(sock_first, buf, MAX_DATA, 0, (struct sockaddr*)&first_addr, &first_addr_len); if(len < 0) { print_error("Second problem with network(not received msg from first sensor), terminating...."); exit(-1); } union msg received_msg; int msg_type = unpack_msg(buf, &received_msg); if(msg_type == DATA_MSG) take_data_msg(received_msg.data); else print_warning("Received unknown bytes"); } usleep(SERVER_TIMEOUT*1000); } return NULL; }
int main(int argc, char *argv[]) { print_init(); if(argc < 4) { printf("Usage: server [first addr] [first port] [last port]\n"); } first_name = argv[1]; port_first = atoi(argv[2]); port_last = atoi(argv[3]); sensor_timeout = DEF_SENSOR_TIMEOUT; sensor_period = DEF_SENSOR_PERIOD; if(initialize_sockets() < 0) { return -1; } initilize_sockaddr(); if(bind(sock_last, (struct sockaddr*) &last_addr, sizeof(last_addr)) < 0) { print_error("Failed to bind socket"); return -1; } print_success("Server launched"); if(initialize_thread() < 0) { print_error("Failed to init thread"); return -1; } if(pthread_create(&reconf_thread, NULL, reconf_fun, NULL) != 0) { return -1; } last_loop(); pthread_join(first_thread, NULL); return 0; }
int main_v1_1(void){ char *nameOfFunction = "Tspi_Context_LoadKeyByUUID02"; TSS_HCONTEXT hContext; TSS_RESULT result; TSS_HKEY hSRK; print_begin_test(nameOfFunction); //Create Result result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create ", result); exit(result); } //Load Key By UUID result = Tspi_Context_LoadKeyByUUID(-1, TSS_PS_TYPE_SYSTEM, SRK_UUID, &hSRK); if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) { if(!checkNonAPI(result)){ print_error(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(result); } else{ print_error_nonapi(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(result); } } else{ print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(0); } }
int main_v1_2( char version ) { char *function = "Tspi_TPM_GetCapability16"; UINT32 pulRespDataLength; BYTE *pRetData; UINT32 subCap, subCapLength, numPcrs; TSS_HCONTEXT hContext; TSS_HTPM hTPM; TSS_RESULT result; UINT32 exitCode; print_begin_test( function ); // Create Context result = Tspi_Context_Create( &hContext ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_Create", result ); exit( result ); } // Connect to Context result = Tspi_Context_Connect( hContext, get_server(GLOBALSERVER) ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_Connect", result ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } // Retrieve TPM object of context result = Tspi_Context_GetTpmObject( hContext, &hTPM ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_GetTpmObject", result ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } subCap = TSS_TPMCAP_PROP_TRANSESSIONS; subCapLength = sizeof(UINT32); result = Tspi_TPM_GetCapability( hTPM, TSS_TPMCAP_PROPERTY, subCapLength, (BYTE *)&subCap, &pulRespDataLength, &pRetData ); if ( result != TSS_SUCCESS ) { if( !(checkNonAPI(result)) ) { print_error( function, result ); exitCode = 1; } else { print_error_nonapi( function, result ); exitCode = 1; } } else { print_success( function, result ); exitCode = 0; if (pulRespDataLength == sizeof(UINT32)) fprintf(stderr, "\tThere are %u available transport sessions in this TPM\n\n", *(UINT32 *)pRetData ); } print_end_test( function ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( exitCode ); }
void pong_handler(void *payload, int payload_size, packet_info_t *packet_info){ calc_rtt(); print_success(); }
int main_v1_2( char version ) { char * function = "Tspi_TPM_Delegate_CreateDelegation02"; TSS_HCONTEXT hContext; TSS_HKEY hSRK; TSS_HTPM hTPM; TSS_HPOLICY hTPMPolicy; TSS_HPOLICY hDelegation = NULL_HPOLICY; TSS_HDELFAMILY hFamily = NULL_HDELFAMILY; TSS_RESULT result; print_begin_test( function ); result = connect_load_all(&hContext, &hSRK, &hTPM); if ( result != TSS_SUCCESS ) { print_error( "connect_load_all", result ); goto done; } result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_GetPolicyObject", result ); goto done; } result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE, TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Policy_SetSecret", result ); goto done; } result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_CreateObject", result ); goto done; } result = Tspi_Policy_SetSecret( hDelegation, TESTSUITE_DELEGATE_SECRET_MODE, TESTSUITE_DELEGATE_SECRET_LEN, TESTSUITE_DELEGATE_SECRET ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Policy_SetSecret", result ); goto done; } result = Tspi_SetAttribUint32(hDelegation, TSS_TSPATTRIB_POLICY_DELEGATION_INFO, TSS_TSPATTRIB_POLDEL_TYPE, TSS_DELEGATIONTYPE_OWNER); if ( result != TSS_SUCCESS ) { print_error( "Tspi_SetAttribUint32", result ); goto done; } result = Tspi_SetAttribUint32(hDelegation, TSS_TSPATTRIB_POLICY_DELEGATION_INFO, TSS_TSPATTRIB_POLDEL_PER1, 0); if ( result != TSS_SUCCESS ) { print_error( "Tspi_SetAttribUint32", result ); goto done; } result = Tspi_SetAttribUint32(hDelegation, TSS_TSPATTRIB_POLICY_DELEGATION_INFO, TSS_TSPATTRIB_POLDEL_PER2, 0); if ( result != TSS_SUCCESS ) { print_error( "Tspi_SetAttribUint32", result ); goto done; } result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily); if ( result != TSS_SUCCESS ) { print_error( "Tspi_TPM_Delegate_AddFamily", result ); goto done; } result = Tspi_TPM_Delegate_CreateDelegation(0xffffffff, 'b', 0, NULL_HPCRS, hFamily, hDelegation); if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) { print_error( function, result ); result = 1; goto done; } else { print_success( function, result ); result = 0; } done: /* Invalidate the family to avoid resource exhaustion */ if (hFamily != NULL_HDELFAMILY) Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); print_end_test( function ); exit( result ); }