void tc_create_policy(TSS_HCONTEXT hContext, UINT32 type, UINT32 flags, TSS_HOBJECT hObject) { TSS_HPOLICY hPolicy; TSS_RESULT result; //Create Policy Object tc_create_object(hContext, type, flags, &hPolicy); //Set Policy Secret result = Tspi_Policy_SetSecret(hPolicy, TESTSUITE_KEY_SECRET_MODE, TESTSUITE_KEY_SECRET_LEN, TESTSUITE_KEY_SECRET); if (result != TSS_SUCCESS) { print_error("Tspi_Policy_SetSecret", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Assign Policy to Object (Key) result = Tspi_Policy_AssignToObject(hPolicy, hObject); if (result != TSS_SUCCESS) { print_error("Tspi_Policy_AssignToObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } }
bool DummyUnixSandbox::box_checker(pid_t box_pid) { int error_id = 0; int err_msg = 0; int err_ret; bool timed_out = false; while ((err_ret = get_error(error_id, err_msg)) != 0) { if (err_ret == -1) { error(5, serror("Error getting errors")); return false; } if (error_id < 0) { warning(5, serror(err_string(error_id), err_msg)); } else { error(5, serror(err_string(error_id), err_msg)); return false; } } // If we arrive here, exec() was successfully executed in the child. auto start = std::chrono::high_resolution_clock::now(); int ret = 0; if (wall_time_limit.microseconds() > 0) { auto now = std::chrono::high_resolution_clock::now(); size_t micros = std::chrono::duration_cast<std::chrono::microseconds>(now-start).count(); bool waited = false; while (micros < wall_time_limit.microseconds()) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); int what = waitpid(box_pid, &ret, WNOHANG); if (what > 0) { waited = true; break; } now = std::chrono::high_resolution_clock::now(); micros = std::chrono::duration_cast<std::chrono::microseconds>(now-start).count(); } if (!waited) { timed_out = true; kill(box_pid, SIGKILL); waitpid(box_pid, &ret, 0); } } else { waitpid(box_pid, &ret, 0); } // The child has exited, collect statistics auto now = std::chrono::high_resolution_clock::now(); return_code = WIFEXITED(ret) ? WEXITSTATUS(ret) : 0; signal = WIFSIGNALED(ret) ? WTERMSIG(ret) : 0; if (timed_out) exit_status = "Timed out"; else exit_status = WIFSIGNALED(ret) ? "Signaled" : "Terminated normally"; wall_time = now-start; struct rusage stats; getrusage(RUSAGE_CHILDREN, &stats); memory_usage = space_limit_t::from_rusage_unit(stats.ru_maxrss); running_time = stats.ru_utime; running_time += stats.ru_stime; return true; }
int main(int argc, const char *argv[]) { int opt; poptContext pc; int opt_version = 0; char *opt_config_file = NULL; int opt_debug = 0; struct gt_config cfg = {0}; int ret; AUTOCLEAN(int werr, waitchildren) = 0; struct poptOption long_options[] = { POPT_AUTOHELP {"config", 'c', POPT_ARG_STRING, &opt_config_file, 0, \ _("Specify a non-default config file"), NULL}, \ {"debug", 'd', POPT_ARG_NONE, &opt_debug, 0, \ _("Enable debugging"), NULL}, \ {"version", '\0', POPT_ARG_NONE, &opt_version, 0, \ _("Print version number and exit"), NULL }, \ POPT_TABLEEND }; pc = poptGetContext(argv[0], argc, argv, long_options, 0); while((opt = poptGetNextOpt(pc)) != -1) { switch(opt) { default: fprintf(stderr, "\n%s %s: %s\n\n", err_string(ERR_BADOPT), poptBadOption(pc, 0), poptStrerror(opt)); poptPrintUsage(pc, stderr, 0); return 1; } } if (opt_version) { puts(VERSION""DISTRO_VERSION""PRERELEASE_VERSION); return 0; } ret = load_config(opt_config_file, &cfg); if (ret) { fprintf(stderr, "Failed to load config file '%s': %s\n", opt_config_file, err_string(ret)); return 2; } for (int i = 0; i < cfg.num_svcs; i++) { ret = runsvc(&cfg.svcs[i]); if (ret) { fprintf(stderr, "Service terminated: %s\n", err_string(ret)); return 3; } } return 0; }
int verify_set_agheader(xfs_mount_t *mp, xfs_buf_t *sbuf, xfs_sb_t *sb, xfs_agf_t *agf, xfs_agi_t *agi, xfs_agnumber_t i) { int rval = 0; int status = XR_OK; int status_sb = XR_OK; status = verify_sb(sb, (i == 0)); if (status != XR_OK) { do_warn(_("bad on-disk superblock %d - %s\n"), i, err_string(status)); } status_sb = compare_sb(mp, sb); if (status_sb != XR_OK) { do_warn(_("primary/secondary superblock %d conflict - %s\n"), i, err_string(status_sb)); } if (status != XR_OK || status_sb != XR_OK) { if (!no_modify) { *sb = mp->m_sb; /* * clear the more transient fields */ sb->sb_inprogress = 1; sb->sb_icount = 0; sb->sb_ifree = 0; sb->sb_fdblocks = 0; sb->sb_frextents = 0; sb->sb_qflags = 0; } rval |= XR_AG_SB; } rval |= secondary_sb_wack(mp, sbuf, sb, i); rval |= verify_set_agf(mp, agf, i); rval |= verify_set_agi(mp, agi, i); return(rval); }
bool verificar_tablas(MYSQL *my_con) { std::vector<std::string> tablas, creates; if(!leer_tablas("c:/prog/test/mydb.dat", tablas, creates)) { std::cout << "Error leyendo las tablas." << std::endl; return -1; } for(size_t i = 0; i < tablas.size(); ++i) { if(!existe_tabla(my_con, tablas[i])) { // Creamos la tabla. std::cout << "Creamos la tabla: " << tablas[i] << std::endl; if(mysql_query(my_con, creates[i].c_str())) { std::string err_string("Error al crear la tabla " + tablas[i]); print_mysql_error(my_con, err_string); } } else { std::cout << "La tabla " << tablas[i] << " ya existe." << std::endl; } } std::cout << "Salimos de verificar_tablas()." << std::endl; return true; }
void tc_create_key(TSS_HCONTEXT hContext, TSS_HKEY hKey, TSS_HKEY hParent, UINT32 flags) { TSS_RESULT result; //Create Policy if (flags & TSS_KEY_AUTHORIZATION) { //Create Usage Policy Object tc_create_policy(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, hKey); if (flags & TSS_KEY_MIGRATABLE) { //Create Migration Policy Object tc_create_policy(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_MIGRATION, hKey); } } //Create Key result = Tspi_Key_CreateKey(hKey, hParent, 0); if (result != TSS_SUCCESS) { print_error("Tspi_Key_CreateKey", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } }
void die_if_err(error_t err) { if( err ) { fprintf(stderr, "Error: %s\nAborting\n", err_string(err)); assert(0); exit(-1); } }
char const *dlerror(void) { char const *err = err_string(); s_err = 0; return err; }
void tc_load_key(TSS_HCONTEXT hContext, TSS_HKEY hKey, TSS_HKEY hParent) { TSS_RESULT result; result = Tspi_Key_LoadKey(hKey, hParent); if (result != TSS_SUCCESS) { print_error("Tspi_Key_LoadKey", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } }
void tc_set_attribdata(TSS_HCONTEXT hContext, TSS_HOBJECT hObject, UINT32 flag, UINT32 subflag, UINT32 blobSize, BYTE *blob) { TSS_RESULT result; result = Tspi_SetAttribData(hObject, flag, subflag, blobSize, blob); if (result != TSS_SUCCESS) { print_error("Tspi_SetAttribData", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } }
void tc_create_object(TSS_HCONTEXT hContext, UINT32 type, UINT32 flags, TSS_HOBJECT *hObject) { TSS_RESULT result; //Create Object result = Tspi_Context_CreateObject(hContext, type, flags, hObject); if (result != TSS_SUCCESS) { print_error("Tspi_Context_CreateObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } }
bool existe_tabla(MYSQL *my_con, std::string &tabla) { std::string consulta = "SHOW TABLES FROM sepyadb LIKE \'" + tabla + "\'"; MYSQL_RES *my_res; bool valor_ret = true; if(mysql_query(my_con, consulta.c_str()) != 0) { std::string err_string("Fallo al consultar existencia de la tabla " + tabla); print_mysql_error(my_con, err_string); valor_ret = false; } else { if((my_res = mysql_store_result(my_con)) != NULL) { // Procesar resultados if(!mysql_num_rows(my_res)) valor_ret = false; // Liberar el resultado de la consulta: mysql_free_result(my_res); } } return valor_ret; }
bool existe_cliente(MYSQL *my_con, int codigo_cliente) { std::string consulta = "SELECT * FROM CLIENTE WHERE cod_cliente=" + utiles::IntToStr(codigo_cliente, 6); MYSQL_RES *my_res; bool valor_ret = false; if(mysql_query(my_con, consulta.c_str()) != 0) { std::string err_string("Fallo al consultar existencia del cliente " + utiles::IntToStr(codigo_cliente, 6)); print_mysql_error(my_con, err_string); valor_ret = false; } else { if((my_res = mysql_store_result(my_con)) != NULL) { // Procesar resultados if(mysql_num_rows(my_res) != 0) valor_ret = true; // Liberar el resultado de la consulta: mysql_free_result(my_res); } } return valor_ret; }
int main_v1_1( void ) { char *function = "Tspi_Key_GetPubKey01"; TSS_HCONTEXT hContext; TSS_HKEY hSRK; TSS_HKEY hKey; TSS_UUID SRKUUID = {0,0,0,0,0,0,0,0,0,0,1}; TSS_UUID migratableSignUUID = {1,2,3,4,5,6,7,8,9,10,2}; TSS_UUID uuid; TSS_RESULT result; UINT32 ulPubKeyLength; BYTE *rgbPubKey; TSS_HPOLICY srkUsagePolicy; TSS_FLAG initFlags = TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048 | TSS_KEY_VOLATILE | TSS_KEY_NO_AUTHORIZATION | TSS_KEY_NOT_MIGRATABLE; print_begin_test( function ); // Create Context result = Tspi_Context_Create( &hContext ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_Create", result ); print_error_exit( function, err_string(result) ); exit( result ); } // Connect to Context result = Tspi_Context_Connect( hContext, get_server(GLOBALSERVER) ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_Connect", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } //Load Key By UUID result = Tspi_Context_LoadKeyByUUID( hContext, TSS_PS_TYPE_SYSTEM, SRK_UUID, &hSRK ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_LoadKeyByUUID (hSRK)", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } #ifndef TESTSUITE_NOAUTH_SRK //Get Policy Object result = Tspi_GetPolicyObject( hSRK, TSS_POLICY_USAGE, &srkUsagePolicy ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_GetPolicyObject", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } //Set Secret result = Tspi_Policy_SetSecret( srkUsagePolicy, TESTSUITE_SRK_SECRET_MODE, TESTSUITE_SRK_SECRET_LEN, TESTSUITE_SRK_SECRET ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Policy_SetSecret", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } #endif //Create Signing Key result = Tspi_Context_CreateObject( hContext, TSS_OBJECT_TYPE_RSAKEY, initFlags, &hKey ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_CreateObject (hKey)", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } result = Tspi_Key_CreateKey( hKey, hSRK, 0 ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Key_CreateKey (hKey)", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } result = Tspi_Key_LoadKey( hKey, hSRK ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Key_LoadKey (hKey)", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } // Get Pub Key result = Tspi_Key_GetPubKey( hKey, &ulPubKeyLength, &rgbPubKey ); if ( result != TSS_SUCCESS ) { if( !(checkNonAPI(result)) ) { print_error( function, result ); } else { print_error_nonapi( function, result ); } } else { result = Tspi_Context_FreeMemory(hContext, rgbPubKey); if (result != TSS_SUCCESS) { print_error("Tspi_Context_FreeMemory ", result); print_error_exit(function, err_string(result)); Tspi_Context_Close(hContext); exit(result); } 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 = "key_auth_chain02"; TSS_HCONTEXT hContext; TSS_HKEY hSRK; TSS_HKEY hKey0, hKey1, hKey2; TSS_RESULT result; TSS_HENCDATA hEncData; TSS_HPOLICY srkUsagePolicy, keyUsagePolicy; int temp; print_begin_test( function ); srand(time(0)); // Create Context result = Tspi_Context_Create( &hContext ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_Create", result ); print_error_exit( function, err_string(result) ); exit( result ); } // Connect to Context result = Tspi_Context_Connect( hContext, NULL ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_Connect", result ); goto done; } //Load Key By UUID result = Tspi_Context_LoadKeyByUUID( hContext, TSS_PS_TYPE_SYSTEM, uuid_2, &hKey2 ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_LoadKeyByUUID (hSRK)", result ); goto done; } result = Tspi_Context_CreateObject( hContext, TSS_OBJECT_TYPE_ENCDATA, TSS_ENCDATA_BIND, &hEncData ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_CreateObject (hEncData)", result ); goto done; } // Data Bind result = Tspi_Data_Bind( hEncData, hKey2, ulDataLength, rgbDataToBind ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Data_Bind", result ); goto done; } result = Tspi_Data_Unbind( hEncData, hKey2, &pulDataLength, &prgbDataToUnBind ); if ( result != TSS_SUCCESS ) { if( !(checkNonAPI(result)) ) { print_error( function, result ); goto done; } else { print_error_nonapi( function, result ); goto done; } } else { if ((pulDataLength == ulDataLength) && !memcmp(prgbDataToUnBind, rgbDataToBind, pulDataLength)) print_success( function, result ); else{ printf("Data doesn't match"); print_error("Data doestn't match: Tspi_Data_Unbind", TSS_E_FAIL); } } #if 0 #ifndef TESTSUITE_NOAUTH_SRK //Get Policy Object result = Tspi_GetPolicyObject( hSRK, TSS_POLICY_USAGE, &srkUsagePolicy ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_GetPolicyObject", result ); goto done; } //Set Secret result = Tspi_Policy_SetSecret( srkUsagePolicy, TESTSUITE_SRK_SECRET_MODE, TESTSUITE_SRK_SECRET_LEN, TESTSUITE_SRK_SECRET ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Policy_SetSecret", result ); goto done; } #endif /* ######## Start Key 0 ######## */ result = Tspi_Context_CreateObject( hContext, TSS_OBJECT_TYPE_RSAKEY, TSS_KEY_SIZE_2048 | TSS_KEY_TYPE_STORAGE | TSS_KEY_NO_AUTHORIZATION, &hKey0 ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_CreateObject (key 0)", result ); goto done; } result = Tspi_Key_CreateKey( hKey0, hSRK, 0 ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Key_CreateKey (key 0)", result ); goto done; } result = Tspi_Context_RegisterKey( hContext, hKey0, TSS_PS_TYPE_SYSTEM, uuid_0, TSS_PS_TYPE_SYSTEM, SRK_UUID ); if ( (result != TSS_SUCCESS) ) { print_error( "Tspi_Context_RegisterKey (uuid_0)", result ); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_0, &hKey0); goto done; } fprintf( stderr, "\t\tKey 0 Finished\n" ); /* ######## End Key 0 ######## */ /* ######## Start Key 1 ######## */ result = Tspi_Context_CreateObject( hContext, TSS_OBJECT_TYPE_RSAKEY, TSS_KEY_AUTHORIZATION, &hKey1 ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_CreateObject (key 1)", result ); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_0, &hKey0); goto done; } result = Tspi_Context_LoadKeyByUUID( hContext, TSS_PS_TYPE_SYSTEM, uuid_0, &hKey0 ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_LoadKeyByUUID (hKey0)", result ); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_0, &hKey0); goto done; } result = Tspi_GetPolicyObject( hKey1, TSS_POLICY_USAGE, &keyUsagePolicy ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_GetPolicyObject", result ); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_0, &hKey0); goto done; } //Set Secret result = Tspi_Policy_SetSecret( keyUsagePolicy, TESTSUITE_KEY_SECRET_MODE, TESTSUITE_KEY_SECRET_LEN, TESTSUITE_KEY_SECRET ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Policy_SetSecret", result ); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_0, &hKey0); goto done; } result = Tspi_Key_CreateKey( hKey1, hKey0, 0 ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Key_CreateKey (key 1)", result ); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_0, &hKey0); goto done; } result = Tspi_Context_RegisterKey( hContext, hKey1, TSS_PS_TYPE_SYSTEM, uuid_1, TSS_PS_TYPE_SYSTEM, uuid_0 ); if ( (result != TSS_SUCCESS) ) { print_error( "Tspi_Context_RegisterKey (uuid_1)", result ); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_0, &hKey0); goto done; } fprintf( stderr, "\t\tKey 1 Finished\n" ); /* ######## End Key 1 ######## */ /* ######## Start Key 2 ######## */ result = Tspi_Context_CreateObject( hContext, TSS_OBJECT_TYPE_RSAKEY, TSS_KEY_NO_AUTHORIZATION, &hKey2 ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_CreateObject (key 2)", result ); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_0, &hKey0); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_1, &hKey1); goto done; } result = Tspi_Key_LoadKey( hKey1, hKey0 ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_LoadKeyByUUID (hKey1)", result ); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_0, &hKey0); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_1, &hKey1); goto done; } result = Tspi_Key_CreateKey( hKey2, hKey1, 0 ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Key_CreateKey (key 2)", result ); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_0, &hKey0); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_1, &hKey1); goto done; } result = Tspi_Context_RegisterKey( hContext, hKey2, TSS_PS_TYPE_SYSTEM, uuid_2, TSS_PS_TYPE_SYSTEM, uuid_1 ); if ( (result != TSS_SUCCESS) ) { print_error( "Tspi_Context_RegisterKey (uuid_2)", result ); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_0, &hKey0); Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, uuid_1, &hKey1); goto done; } fprintf( stderr, "\t\tKey 2 Finished\n" ); /* ######## End Key 2 ######## */ #endif Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); done: print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); }
int main_v1_2(char version) { char *nameOfFunction = "Tspi_Nv_WriteValue04"; TSS_HCONTEXT hContext = NULL_HCONTEXT; TSS_HNVSTORE hNVStore = 0;//NULL_HNVSTORE TSS_HOBJECT hPolObject = NULL_HOBJECT; BYTE *auth = "123456"; UINT32 auth_length = 6; BYTE *data = "1234567890"; TSS_RESULT result; print_begin_test(nameOfFunction); //Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create ", result); print_error_exit(nameOfFunction, err_string(result)); exit(result); } //Connect Context result = Tspi_Context_Connect(hContext,NULL); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Create TPM NV object */ result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_NV, 0,&hNVStore); if (result != TSS_SUCCESS) { print_error("Tspi_Context_CreateObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Create policy object for the NV object*/ result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hPolObject); if (result != TSS_SUCCESS) { print_error("Tspi_Context_CreateObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set password */ result = Tspi_Policy_SetSecret(hPolObject, TSS_SECRET_MODE_PLAIN, auth_length, auth); if (result != TSS_SUCCESS) { print_error("Tspi_Policy_SetSecret", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set password */ result = Tspi_Policy_AssignToObject(hPolObject, hNVStore); if (result != TSS_SUCCESS) { print_error("Tspi_Policy_AssignToObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set the index to be defined. */ result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_INDEX, 0,0x00050001); if (result != TSS_SUCCESS) { print_error("Tspi_SetAttribUint32 for setting NV index", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } result = Tspi_NV_WriteValue(hNVStore, /*offset*/0,/*datalength*/10, data); #ifdef NV_LOCKED if (TSS_ERROR_CODE(result)== TPM_E_BADINDEX) { print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(0); } else{ print_error("Tspi_NV_WriteValue", result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); if ( result == TSS_SUCCESS ) exit(-1); exit(result); } #else if (TSS_ERROR_CODE(result)== TPM_E_BADINDEX) { print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(0); } else{ print_error("Tspi_NV_WriteValue", result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); if ( result == TSS_SUCCESS ) exit(-1); exit(result); } #endif }
main_v1_2(char version) { TSS_HCONTEXT hContext; TSS_HKEY hSRK; TSS_HTPM hTPM; TSS_HPOLICY hTpmUsagePolicy; TSS_FLAG initFlags; TSS_HKEY hSrcKey; TSS_HKEY hDestKey; TSS_HKEY hMaKey[MA_KEY_COUNT]; TSS_HKEY hCmkKey; TSS_HKEY hNewKey; TSS_HMIGDATA hMigData; TSS_HHASH hHash; UINT32 blobSize; BYTE *blob; UINT32 randomSize; BYTE *random; int i; TSS_RESULT result; print_begin_test(nameOfFunction); result = connect_load_all(&hContext, &hSRK, &hTPM); if ( result != TSS_SUCCESS ) { print_error( "connect_load_all", result ); exit(result); } //Get TPM Policy Object result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hTpmUsagePolicy); if (result != TSS_SUCCESS) { print_error("Tspi_GetPolicyObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Set Secret result = Tspi_Policy_SetSecret(hTpmUsagePolicy, TESTSUITE_OWNER_SECRET_MODE, TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET); if (result != TSS_SUCCESS) { print_error("Tspi_Policy_SetSecret", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } /***** Create Overall Source Parent key *****/ initFlags = TSS_KEY_STRUCT_KEY12 | TSS_KEY_TYPE_STORAGE | TSS_KEY_SIZE_2048 | TSS_KEY_VOLATILE | TSS_KEY_AUTHORIZATION; tc_create_object(hContext, TSS_OBJECT_TYPE_RSAKEY, initFlags, &hSrcKey); tc_create_key(hContext, hSrcKey, hSRK, initFlags); tc_load_key(hContext, hSrcKey, hSRK); /***** Create Overall Destination Parent key *****/ initFlags = TSS_KEY_STRUCT_KEY12 | TSS_KEY_TYPE_STORAGE | TSS_KEY_SIZE_2048 | TSS_KEY_VOLATILE | TSS_KEY_AUTHORIZATION; tc_create_object(hContext, TSS_OBJECT_TYPE_RSAKEY, initFlags, &hDestKey); tc_create_key(hContext, hDestKey, hSRK, initFlags); tc_load_key(hContext, hDestKey, hSRK); /***** Create MAs and MSA list *****/ //Create MigData Object tc_create_object(hContext, TSS_OBJECT_TYPE_MIGDATA, 0, &hMigData); for (i = 0; i < MA_KEY_COUNT; i++) { //Create Key Object initFlags = TSS_KEY_STRUCT_KEY12 | TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048 | TSS_KEY_VOLATILE | TSS_KEY_AUTHORIZATION; tc_create_object(hContext, TSS_OBJECT_TYPE_RSAKEY, initFlags, &hMaKey[i]); tc_create_key(hContext, hMaKey[i], hSrcKey, initFlags); //Get PubKey Blob tc_get_attribdata(hContext, hMaKey[i], TSS_TSPATTRIB_KEY_BLOB, TSS_TSPATTRIB_KEYBLOB_PUBLIC_KEY, &blobSize, &blob); //Add PubKey Blob to the MSA list tc_set_attribdata(hContext, hMigData, TSS_MIGATTRIB_MIGRATIONBLOB, TSS_MIGATTRIB_MIG_MSALIST_PUBKEY_BLOB, blobSize, blob); } //Grant Owner Approval of MAs result = Tspi_TPM_CMKApproveMA(hTPM, hMigData); if (result != TSS_SUCCESS) { print_error("Tspi_TPM_CMKApproveMA", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } /***** Create a CMK ****/ initFlags = TSS_KEY_STRUCT_KEY12 | TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048 | TSS_KEY_VOLATILE | TSS_KEY_AUTHORIZATION | TSS_KEY_MIGRATABLE | TSS_KEY_CERTIFIED_MIGRATABLE; tc_create_object(hContext, TSS_OBJECT_TYPE_RSAKEY, initFlags, &hCmkKey); //Get and Assign MA/MSA information tc_get_attribdata(hContext, hMigData, TSS_MIGATTRIB_AUTHORITY_DATA, TSS_MIGATTRIB_AUTHORITY_DIGEST, &blobSize, &blob); tc_set_attribdata(hContext, hCmkKey, TSS_TSPATTRIB_KEY_CMKINFO, TSS_TSPATTRIB_KEYINFO_CMK_MA_DIGEST, blobSize, blob); tc_get_attribdata(hContext, hMigData, TSS_MIGATTRIB_AUTHORITY_DATA, TSS_MIGATTRIB_AUTHORITY_APPROVAL_HMAC, &blobSize, &blob); tc_set_attribdata(hContext, hCmkKey, TSS_TSPATTRIB_KEY_CMKINFO, TSS_TSPATTRIB_KEYINFO_CMK_MA_APPROVAL, blobSize, blob); tc_create_key(hContext, hCmkKey, hSrcKey, initFlags); /***** Authorize migration to the Dest key *****/ //Authorize Migration Ticket result = Tspi_TPM_AuthorizeMigrationTicket(hTPM, hDestKey, TSS_MS_RESTRICT_APPROVE_DOUBLE, &blobSize, &blob); if (result != TSS_SUCCESS) { print_error("Tspi_TPM_AuthorizeMigrationTicket", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Save Ticket tc_set_attribdata(hContext, hMigData, TSS_MIGATTRIB_MIGRATIONTICKET, 0, blobSize, blob); /***** Sign the migration ticket *****/ //Get PubKey Blob of CMK tc_get_attribdata(hContext, hCmkKey, TSS_TSPATTRIB_KEY_BLOB, TSS_TSPATTRIB_KEYBLOB_PUBLIC_KEY, &blobSize, &blob); tc_set_attribdata(hContext, hMigData, TSS_MIGATTRIB_MIGRATIONBLOB, TSS_MIGATTRIB_MIG_SOURCE_PUBKEY_BLOB, blobSize, blob); //Get PubKey Blob of destination CMK parent tc_get_attribdata(hContext, hDestKey, TSS_TSPATTRIB_KEY_BLOB, TSS_TSPATTRIB_KEYBLOB_PUBLIC_KEY, &blobSize, &blob); tc_set_attribdata(hContext, hMigData, TSS_MIGATTRIB_MIGRATIONBLOB, TSS_MIGATTRIB_MIG_DESTINATION_PUBKEY_BLOB, blobSize, blob); //Get PubKey Blob of MA tc_get_attribdata(hContext, hMaKey[0], TSS_TSPATTRIB_KEY_BLOB, TSS_TSPATTRIB_KEYBLOB_PUBLIC_KEY, &blobSize, &blob); tc_set_attribdata(hContext, hMigData, TSS_MIGATTRIB_MIGRATIONBLOB, TSS_MIGATTRIB_MIG_AUTHORITY_PUBKEY_BLOB, blobSize, blob); //Get Ticket Signature Data tc_create_object(hContext, TSS_OBJECT_TYPE_HASH, TSS_HASH_SHA1, &hHash); tc_get_attribdata(hContext, hMigData, TSS_MIGATTRIB_MIG_AUTH_DATA, TSS_MIGATTRIB_MIG_AUTH_AUTHORITY_DIGEST, &blobSize, &blob); result = Tspi_Hash_UpdateHashValue(hHash, blobSize, blob); if (result != TSS_SUCCESS) { print_error("Tspi_Hash_UpdateHashValue", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } tc_get_attribdata(hContext, hMigData, TSS_MIGATTRIB_MIG_AUTH_DATA, TSS_MIGATTRIB_MIG_AUTH_DESTINATION_DIGEST, &blobSize, &blob); result = Tspi_Hash_UpdateHashValue(hHash, blobSize, blob); if (result != TSS_SUCCESS) { print_error("Tspi_Hash_UpdateHashValue", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } tc_get_attribdata(hContext, hMigData, TSS_MIGATTRIB_MIG_AUTH_DATA, TSS_MIGATTRIB_MIG_AUTH_SOURCE_DIGEST, &blobSize, &blob); result = Tspi_Hash_UpdateHashValue(hHash, blobSize, blob); if (result != TSS_SUCCESS) { print_error("Tspi_Hash_UpdateHashValue", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } result = Tspi_Hash_GetHashValue(hHash, &blobSize, &blob); if (result != TSS_SUCCESS) { print_error("Tspi_Hash_GetHashValue", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Load Verify Key tc_load_key(hContext, hMaKey[0], hSrcKey); //Generate Ticket Signature result = Tspi_Hash_Sign(hHash, hMaKey[0], &blobSize, &blob); if (result != TSS_SUCCESS) { print_error("Tspi_Hash_Sign", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Save Ticket Signature tc_set_attribdata(hContext, hMigData, TSS_MIGATTRIB_TICKET_DATA, TSS_MIGATTRIB_TICKET_SIG_VALUE, blobSize, blob); //Create Ticket result = Tspi_TPM_CMKCreateTicket(hTPM, hMaKey[0], hMigData); if (result != TSS_SUCCESS) { print_error("Tspi_TPM_CMKCreateTicket", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } /***** Create a migration blob *****/ //Create Blob result = Tspi_Key_CMKCreateBlob(hCmkKey, hSrcKey, hMigData, &randomSize, &random); if (result != TSS_SUCCESS) { print_error("Tspi_TPM_CMKCreateBlob", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } /***** Create a CMK ticket for the destination TPM *****/ //We are using the same TPM so the next steps are not necessary, but are //done for procedural info //Get Ticket Signature Data tc_create_object(hContext, TSS_OBJECT_TYPE_HASH, TSS_HASH_SHA1, &hHash); tc_get_attribdata(hContext, hMigData, TSS_MIGATTRIB_MIG_AUTH_DATA, TSS_MIGATTRIB_MIG_AUTH_AUTHORITY_DIGEST, &blobSize, &blob); result = Tspi_Hash_UpdateHashValue(hHash, blobSize, blob); if (result != TSS_SUCCESS) { print_error("Tspi_Hash_UpdateHashValue", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } tc_get_attribdata(hContext, hMigData, TSS_MIGATTRIB_MIG_AUTH_DATA, TSS_MIGATTRIB_MIG_AUTH_DESTINATION_DIGEST, &blobSize, &blob); result = Tspi_Hash_UpdateHashValue(hHash, blobSize, blob); if (result != TSS_SUCCESS) { print_error("Tspi_Hash_UpdateHashValue", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } tc_get_attribdata(hContext, hMigData, TSS_MIGATTRIB_MIG_AUTH_DATA, TSS_MIGATTRIB_MIG_AUTH_SOURCE_DIGEST, &blobSize, &blob); result = Tspi_Hash_UpdateHashValue(hHash, blobSize, blob); if (result != TSS_SUCCESS) { print_error("Tspi_Hash_UpdateHashValue", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } result = Tspi_Hash_GetHashValue(hHash, &blobSize, &blob); if (result != TSS_SUCCESS) { print_error("Tspi_Hash_GetHashValue", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Load Verify Key tc_load_key(hContext, hMaKey[0], hSrcKey); //Generate Ticket Signature result = Tspi_Hash_Sign(hHash, hMaKey[0], &blobSize, &blob); if (result != TSS_SUCCESS) { print_error("Tspi_Hash_Sign", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Save Ticket Signature tc_set_attribdata(hContext, hMigData, TSS_MIGATTRIB_TICKET_DATA, TSS_MIGATTRIB_TICKET_SIG_VALUE, blobSize, blob); //Create Ticket result = Tspi_TPM_CMKCreateTicket(hTPM, hMaKey[0], hMigData); if (result != TSS_SUCCESS) { print_error("Tspi_TPM_CMKCreateTicket", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } /***** Migrate the key *****/ initFlags = TSS_KEY_STRUCT_KEY12 | TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048 | TSS_KEY_VOLATILE | TSS_KEY_AUTHORIZATION | TSS_KEY_MIGRATABLE | TSS_KEY_CERTIFIED_MIGRATABLE; tc_create_object(hContext, TSS_OBJECT_TYPE_RSAKEY, initFlags, &hNewKey); result = Tspi_Key_CMKConvertMigration(hNewKey, hDestKey, hMigData, randomSize, random); 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); } } tc_load_key(hContext, hNewKey, hDestKey); print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(0); }
char * renice_procs(char *str) { register char negate; int prio; int procnum; int uid; ERR_RESET; uid = getuid(); /* allow for negative priority values */ if ((negate = (*str == '-')) != 0) { /* move past the minus sign */ str++; } /* use procnum as a temporary holding place and get the number */ procnum = scanint(str, &prio); /* negate if necessary */ if (negate) { prio = -prio; } #if defined(PRIO_MIN) && defined(PRIO_MAX) /* check for validity */ if (procnum == -1 || prio < PRIO_MIN || prio > PRIO_MAX) { return (" bad priority value"); } #endif /* move to the first process number */ if ((str = next_field(str)) == NULL) { return (" no processes specified"); } #ifdef HAVE_SETPRIORITY /* loop thru the process numbers, renicing each one */ do { if (scanint(str, &procnum) == -1) { ERROR(str, 0); } /* check process owner if we're not root */ else if (uid && (uid != proc_owner(procnum))) { ERROR(str, EACCES); } else if (setpriority(PRIO_PROCESS, procnum, prio) == -1) { ERROR(str, errno); } } while ((str = next_field(str)) != NULL); /* return appropriate error string */ return (err_string()); #else return (" operation not supported"); #endif }
char * kill_procs(char *str) { register char *nptr; int signum = SIGTERM; /* default */ int procnum; struct sigdesc *sigp; int uid; /* reset error array */ ERR_RESET; /* remember our uid */ uid = getuid(); /* skip over leading white space */ while (isspace(*str)) str++; if (str[0] == '-') { /* explicit signal specified */ if ((nptr = next_field(str)) == NULL) { return (" kill: no processes specified"); } if (isdigit(str[1])) { (void) scanint(str + 1, &signum); if (signum <= 0 || signum >= NSIG) { return (" invalid signal number"); } } else { /* translate the name into a number */ for (sigp = sigdesc; sigp->name != NULL; sigp++) { if (strcmp(sigp->name, str + 1) == 0) { signum = sigp->number; break; } } /* was it ever found */ if (sigp->name == NULL) { return (" bad signal name"); } } /* put the new pointer in place */ str = nptr; } /* loop thru the string, killing processes */ do { if (scanint(str, &procnum) == -1) { ERROR(str, 0); } else { /* check process owner if we're not root */ if (uid && (uid != proc_owner(procnum))) { ERROR(str, EACCES); } /* go in for the kill */ else if (kill(procnum, signum) == -1) { /* chalk up an error */ ERROR(str, errno); } } } while ((str = next_field(str)) != NULL); /* return appropriate error string */ return (err_string()); }
main_v1_1(void){ char *nameOfFunction = "Tspi_Key_CreateMigrationBlob03"; TSS_HCONTEXT hContext; TSS_HKEY hSRK; TSS_HKEY hKey; UINT32 TargetPubKeyLength; BYTE *TargetPublicKeyData; BYTE *MigTicket; UINT32 TicketLength; BYTE *randomData; UINT32 randomLength; UINT32 migBlobLength; BYTE *migBlob; UINT32 blobLength; TSS_RESULT result; TSS_HTPM hTPM; TSS_HPOLICY srkUsagePolicy, keyUsagePolicy, keyMigPolicy, tpmUsagePolicy; print_begin_test(nameOfFunction); //Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create ", result); print_error_exit(nameOfFunction, err_string(result)); exit(result); } //Connect Context result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER)); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect", result); print_error_exit(nameOfFunction, err_string(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); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Load Key By UUID result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM, SRK_UUID, &hSRK); if (result != TSS_SUCCESS) { print_error("Tspi_Context_LoadKeyByUUID for hSRK", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } #ifndef TESTSUITE_NOAUTH_SRK //Get Policy Object result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &srkUsagePolicy); if (result != TSS_SUCCESS) { print_error("Tspi_GetPolicyObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Set Secret result = Tspi_Policy_SetSecret(srkUsagePolicy, TESTSUITE_SRK_SECRET_MODE, TESTSUITE_SRK_SECRET_LEN, TESTSUITE_SRK_SECRET); if (result != TSS_SUCCESS) { print_error("Tspi_Policy_SetSecret", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } #endif //Get Policy Object result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &tpmUsagePolicy); if (result != TSS_SUCCESS) { print_error("Tspi_GetPolicyObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Set Secret result = Tspi_Policy_SetSecret(tpmUsagePolicy, TESTSUITE_OWNER_SECRET_MODE, TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET); if (result != TSS_SUCCESS) { print_error("Tspi_Policy_SetSecret", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Create Object result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY, TSS_KEY_TYPE_BIND | TSS_KEY_SIZE_2048 | TSS_KEY_NO_AUTHORIZATION | TSS_KEY_NOT_MIGRATABLE, &hKey); if (result != TSS_SUCCESS) { print_error("Tspi_Context_CreateObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Create Signing Key result = Tspi_Key_CreateKey(hKey, hSRK, 0); if (result != TSS_SUCCESS) { print_error("Tspi_Key_CreateKey", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); Tspi_Context_CloseObject(hContext, hKey); exit(result); } //Authorize Migration Ticket result = Tspi_TPM_AuthorizeMigrationTicket(hTPM, hKey, TSS_MS_REWRAP, &TicketLength, &MigTicket); if (result != TSS_SUCCESS) { print_error("Tpsi_TPM_AuthorizeMigrationTicket ", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); Tspi_Context_CloseObject(hContext, hKey); exit(result); } //Create Migration Blob result = Tspi_Key_CreateMigrationBlob(-1, hSRK, TicketLength, MigTicket, &randomLength, &randomData, &migBlobLength, &migBlob); 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_CloseObject(hContext, hKey); 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, hKey); Tspi_Context_Close(hContext); exit(result); } } else{ print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_CloseObject(hContext, hKey); Tspi_Context_Close(hContext); exit(0); } }
main_v1_1(void){ char *nameOfFunction = "Tspi_Key_LoadKey01"; TSS_HCONTEXT hContext; TSS_HTPM hTPM; TSS_FLAG initFlags; TSS_HKEY hKey; TSS_HKEY hSRK; TSS_RESULT result; TSS_UUID uuid; TSS_HPOLICY srkUsagePolicy, keyUsagePolicy, keyMigPolicy; initFlags = TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048 | TSS_KEY_VOLATILE | TSS_KEY_NO_AUTHORIZATION | TSS_KEY_NOT_MIGRATABLE; print_begin_test(nameOfFunction); //Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect", result); print_error_exit(nameOfFunction, err_string(result)); exit(result); } //Connect Context result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER)); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Create Object result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY, initFlags, &hKey); if (result != TSS_SUCCESS) { print_error("Tspi_Context_CreateObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Load Key By UUID result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM, SRK_UUID, &hSRK); if (result != TSS_SUCCESS) { print_error("Tspi_Context_LoadKeyByUUID", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_CloseObject(hContext, hKey); Tspi_Context_Close(hContext); exit(result); } #ifndef TESTSUITE_NOAUTH_SRK //Get Policy Object result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &srkUsagePolicy); if (result != TSS_SUCCESS) { print_error("Tspi_GetPolicyObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_CloseObject(hContext, hKey); Tspi_Context_Close(hContext); exit(result); } //Set Secret result = Tspi_Policy_SetSecret(srkUsagePolicy, TESTSUITE_SRK_SECRET_MODE, TESTSUITE_SRK_SECRET_LEN, TESTSUITE_SRK_SECRET); if (result != TSS_SUCCESS) { print_error("Tspi_Policy_SetSecret", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_CloseObject(hContext, hKey); Tspi_Context_Close(hContext); exit(result); } #endif //Create Key result = Tspi_Key_CreateKey(hKey, hSRK, 0); if (result != TSS_SUCCESS) { print_error("Tspi_Key_Create Key", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_CloseObject(hContext, hKey); Tspi_Context_Close(hContext); exit(result); } //Load Key (hKey) result = Tspi_Key_LoadKey(hKey, hSRK); if (result != TSS_SUCCESS){ if(!checkNonAPI(result)){ print_error(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_CloseObject(hContext, hKey); 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, hKey); Tspi_Context_Close(hContext); exit(result); } } else{ print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_CloseObject(hContext, hKey); Tspi_Context_Close(hContext); exit(0); } }
int main_v1_1( void ) { char *function = "key_auth_check01"; TSS_HCONTEXT hContext; UINT32 exitCode; TSS_HKEY hSRK; TSS_HKEY hMSigningKey; TSS_UUID migratableSignUUID = {0x1, 0x55, 0x67, 0x8, 0x5, { 6, 7, 8, 9, 10, 2 } }; TSS_HHASH hHash; BYTE *prgbSignature; UINT32 pulSignatureLength; TSS_RESULT result; TSS_HPOLICY srkUsagePolicy, keyUsagePolicy; print_begin_test( function ); // Create Context result = Tspi_Context_Create( &hContext ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_Create", result ); print_error_exit( function, err_string(result) ); exit( result ); } // Connect to Context result = Tspi_Context_Connect( hContext, get_server(GLOBALSERVER) ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_Connect", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } //Load Key By UUID result = Tspi_Context_LoadKeyByUUID( hContext, TSS_PS_TYPE_SYSTEM, SRK_UUID, &hSRK ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_LoadKeyByUUID (hSRK)", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } #ifndef TESTSUITE_NOAUTH_SRK //Get Policy Object result = Tspi_GetPolicyObject( hSRK, TSS_POLICY_USAGE, &srkUsagePolicy ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_GetPolicyObject", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } //Set Secret result = Tspi_Policy_SetSecret( srkUsagePolicy, TESTSUITE_SRK_SECRET_MODE, TESTSUITE_SRK_SECRET_LEN, TESTSUITE_SRK_SECRET ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Policy_SetSecret", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } #endif //Create Signing Key result = Tspi_Context_CreateObject( hContext, TSS_OBJECT_TYPE_RSAKEY, TSS_KEY_SIZE_2048 | TSS_KEY_TYPE_SIGNING | TSS_KEY_AUTHORIZATION, &hMSigningKey ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_CreateObject (signing key)", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } // get signing key's policy result = Tspi_GetPolicyObject( hMSigningKey, TSS_POLICY_USAGE, &keyUsagePolicy ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_GetPolicyObject", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } //Set Secret result = Tspi_Policy_SetSecret( keyUsagePolicy, TESTSUITE_KEY_SECRET_MODE, TESTSUITE_KEY_SECRET_LEN, TESTSUITE_KEY_SECRET ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Policy_SetSecret", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } result = Tspi_Key_CreateKey( hMSigningKey, hSRK, 0 ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Key_CreateKey (signing key)", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } result = Tspi_Key_LoadKey( hMSigningKey, hSRK ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_LoadKey (hMSigningKey)", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } // create hash result = Tspi_Context_CreateObject( hContext, TSS_OBJECT_TYPE_HASH, TSS_HASH_SHA1, &hHash ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_CreateObject (hash)", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } result = Tspi_Hash_UpdateHashValue( hHash, 20, "Je pense, danc je s" ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Hash_SetHashValue", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } result = Tspi_Hash_Sign( hHash, hMSigningKey, &pulSignatureLength, &prgbSignature ); if ( result != TSS_SUCCESS ) { if( !(checkNonAPI(result)) ) { print_error( function, result ); exitCode = 1; } else { print_error_nonapi( function, result ); exitCode = 1; } } else { result = Tspi_Context_RegisterKey(hContext, hMSigningKey, TSS_PS_TYPE_SYSTEM, migratableSignUUID, TSS_PS_TYPE_SYSTEM, SRK_UUID); if (result != TSS_SUCCESS) { print_error( "Tspi_Context_RegisterKey", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } print_success( function, result ); exitCode = 0; } print_end_test( function ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( exitCode ); }
int main_v1_2(char version) { char *function = "Tspi_PcrComposite_GetPcrLocality01"; TSS_HCONTEXT hContext; TSS_HPCRS hPcrComposite; TSS_RESULT result; UINT32 pLocalityValue; print_begin_test( function ); // Create Context result = Tspi_Context_Create( &hContext ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_Create", result ); print_error_exit( function, err_string(result) ); exit( result ); } // create object result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_PCRS, TSS_PCRS_STRUCT_INFO_LONG, &hPcrComposite); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_CreateObject (hPcrComposite)", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } result = Tspi_PcrComposite_GetPcrLocality( hPcrComposite, &pLocalityValue ); if ( result != TSS_SUCCESS ) { if( !(checkNonAPI(result)) ) { print_error( function, result ); print_end_test( function ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit(result); } else { print_error_nonapi( function, result ); print_end_test( function ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit(result); } } else { print_success( function, result ); print_end_test( function ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( 0 ); } }
void warn_if_err(error_t err) { if( err ) { fprintf(stderr, "Warning: %s\nContinuing\n", err_string(err)); } }
int main_v1_2(char version) { char *nameOfFunction = "Tspi_Nv_DefineSpace12"; TSS_HCONTEXT hContext = NULL_HCONTEXT; TSS_HNVSTORE hNVStore = 0;//NULL_HNVSTORE TSS_HPOLICY hPolicy = NULL_HPOLICY; TSS_HTPM hTPM = NULL_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); print_error_exit(nameOfFunction, err_string(result)); exit(result); } //Connect Context result = Tspi_Context_Connect(hContext,NULL); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Create TPM NV object */ result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_NV, 0,&hNVStore); if (result != TSS_SUCCESS) { print_error("Tspi_Context_CreateObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set the index to be defined. */ result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_INDEX, 0,0x0000d); if (result != TSS_SUCCESS) { print_error("Tspi_SetAttribUint32 for setting NV index", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set the permission for the index. */ result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_PERMISSIONS, 0, 0x2000); if (result != TSS_SUCCESS) { print_error("Tspi_SetAttribUint32 for setting permission", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set the data size to be defined. */ result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_DATASIZE, 0, 0xa); if (result != TSS_SUCCESS) { print_error("Tspi_SetAttribUint32 for setting data size", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /*Define NV space*/ result = Tspi_NV_DefineSpace(hNVStore, 0, 0); #ifdef NV_LOCKED if (TSS_ERROR_CODE(result)== TPM_E_OWNER_SET||TSS_ERROR_CODE(result)==TPM_E_BAD_PRESENCE ) { print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(0); } else{ print_error("Tspi_NV_DefineSpace", result); print_end_test(nameOfFunction); if ( result == TSS_SUCCESS ) { #ifdef CLEAR_TEST_INDEX Tspi_Context_GetTpmObject(hContext, &hTPM); Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hPolicy); Tspi_Policy_SetSecret(hPolicy, TESTSUITE_OWNER_SECRET_MODE, TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET); Tspi_NV_ReleaseSpace(hNVStore); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); #endif exit(-1); } Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } #else if (result== TSS_SUCCESS) { print_success(nameOfFunction, result); print_end_test(nameOfFunction); #ifdef CLEAR_TEST_INDEX Tspi_Context_GetTpmObject(hContext, &hTPM); Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hPolicy); Tspi_Policy_SetSecret(hPolicy, TESTSUITE_OWNER_SECRET_MODE, TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET); Tspi_NV_ReleaseSpace(hNVStore); #endif Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(0); } else{ print_error("Tspi_NV_DefineSpace", result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } #endif }
int main(int argc, char *argv[]) { TSS_HCONTEXT hContext; TSS_RESULT result; TSS_HTPM hTPM; TSS_HPOLICY hPolicy; char *credential_filename = DEFAULT_CREDENTIAL_FILENAME; UINT32 nonceVerifierLength; BYTE *nonceVerifier; TSS_HDAA hDAA; TSS_DAA_CREDENTIAL *hDaaCredential; TSS_DAA_SIGN_DATA signData; TSS_DAA_SIGNATURE daaSignature; TSS_DAA_SELECTED_ATTRIB revealAttributes; char *szTpmPasswd = DEFAULT_OWN_PASSWD; char *message = NULL; BYTE **attributes = NULL; FILE *file; char *param; int i, length, rv; bi_ptr random = NULL; TSS_BOOL isCorrect; EVP_MD_CTX *mdctx; TSS_HKEY hKEY; init_tss_version( &signData); init_tss_version( &daaSignature); init_tss_version( &revealAttributes); i = 1; while( i < argc) { param = argv[ i]; if ( strcmp( param, "-m") == 0 || strcmp( param, "--message") == 0) { i++; if( i == argc) return print_usage( argv[0]); message = argv[i]; } else if( strcmp( param, "-cr") == 0 || strcmp( param, "--credential") == 0){ i++; if( i == argc) return print_usage( argv[0]); credential_filename = argv[i]; } else if( strcmp( param, "-pw") == 0 || strcmp( param, "--passwd") == 0){ i++; if( i == argc) return print_usage( argv[0]); szTpmPasswd = argv[i]; } else { fprintf(stderr, "%s:unrecognized option `%s'\n", argv[0], param); return print_usage( argv[0]); } i++; } bi_init( NULL); printf("Loading credential: %s ", credential_filename); file = fopen( credential_filename, "r"); if( (hDaaCredential = load_TSS_DAA_CREDENTIAL( file)) == 0) { LogError( "[test_join]: Error when loading \'%s\': %s\n", credential_filename, strerror( errno)); result = TSS_E_FAIL; goto out_close; } fclose( file); printf("Done\n"); // Create Context LogDebug("Create Context"); result = Tspi_Context_Create( &hContext ); if ( result != TSS_SUCCESS ) { LogError( "Tspi_Context_Create %d\n", result ); goto out; } // Connect to Context result = Tspi_Context_Connect( hContext, NULL ); if ( result != TSS_SUCCESS) goto out_close; printf("\nConnect to the context: %X\n", hContext); if( (result = Tspi_Context_GetTpmObject( hContext, &hTPM)) != TSS_SUCCESS) goto out_close; // Get the correct policy using the TPM ownership PASSWD if( (result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hPolicy)) != TSS_SUCCESS) goto out_close; if( (result = Tspi_Policy_SetSecret( hPolicy, TSS_SECRET_MODE_PLAIN, strlen( szTpmPasswd), szTpmPasswd)) != TSS_SUCCESS) goto out_close; LogDebug("Tspi_Policy_SetSecret hPolicy received;%d", hPolicy); //Create Object result = obj_daa_add( hContext, &hDAA); if (result != TSS_SUCCESS) { LogError("Tspi_Context_CreateObject:%d", result); Tspi_Context_Close(hContext); LogError("%s: %s", argv[0], err_string(result)); exit(result); } LogDebug("created DAA object:%X", hDAA); // TODO: verifier base name ?? result = Tspi_DAA_VerifyInit( hDAA, // in &nonceVerifierLength, // out &nonceVerifier, // out 0, //baseNameLength, // out NULL //baseName // out ); if (result != TSS_SUCCESS) goto out_close; LogDebug("Verify Init return nonceVerifier [%s]", dump_byte_array( nonceVerifierLength, nonceVerifier)); create_TSS_DAA_SELECTED_ATTRIB( &revealAttributes, 5, 0, 1, 1, 0, 0); mdctx = EVP_MD_CTX_create(); // create the TSS_DAA_SIGN_DATA struct // .selector: 0 -> payload contains a handle to an AIK // 1 -> payload contains a hashed message if( message != NULL) { signData.selector = TSS_FLAG_DAA_SIGN_MESSAGE_HASH; signData.payloadFlag = TSS_FLAG_DAA_SIGN_MESSAGE_HASH; EVP_DigestInit(mdctx, DAA_PARAM_get_message_digest()); EVP_DigestUpdate(mdctx, (BYTE *)message, strlen( message)); signData.payloadLength = EVP_MD_CTX_size(mdctx); signData.payload = (BYTE *)EVP_MD_CTX_create(); EVP_DigestFinal(mdctx, signData.payload, NULL); } else { signData.selector = TSS_FLAG_DAA_SIGN_IDENTITY_KEY; result = Tspi_Context_CreateObject( hContext, // in TSS_OBJECT_TYPE_RSAKEY, // in TSS_KEY_SIZE_2048, // in &hKEY // out ); if( result != TSS_SUCCESS) goto out_close; } result = Tspi_TPM_DAA_Sign( hDAA, // in hTPM, // in (TSS_HKEY)hDaaCredential, // in revealAttributes, // in 0, // verifierBaseNameLength, // in NULL, // verifierBaseName, // in nonceVerifierLength, // in nonceVerifier, // in signData, // in &daaSignature // out ); if (result != TSS_SUCCESS) goto out_close; LogDebug("TPM_DAA_Sign return daaSignature [%s]", dump_byte_array( nonceVerifierLength, nonceVerifier)); // generate attributes list but without copying the not revealed ones attributes = malloc( sizeof(BYTE *) * hDaaCredential->attributesLength); for( i=0; i < (int)(hDaaCredential->attributesLength); i++) { if( revealAttributes.indicesList[i]) { attributes[i] = (BYTE *)malloc( DAA_PARAM_SIZE_F_I / 8); memcpy( attributes[i], hDaaCredential->attributes[i], DAA_PARAM_SIZE_F_I / 8); } else { attributes[i] = NULL; } } result = Tspi_DAA_VerifySignature( hDAA, // in daaSignature, // in (TSS_HKEY)&(hDaaCredential->issuerPK), // in signData, // in hDaaCredential->attributesLength, // in attributes, // in nonceVerifierLength, // in nonceVerifier, // in 0, //baseNameLength, //in NULL, // in &isCorrect // out ); printf("Signature correct:%s\n", ( isCorrect ? "yes" : "no")); out_close: EVP_MD_CTX_destroy(mdctx); if( attributes != NULL) { for( i=0; i<(int)hDaaCredential->attributesLength; i++) { if( attributes[i] != NULL) free( attributes[i]); } free( attributes); } if( random != NULL) bi_free_ptr( random); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); out: bi_release(); LogDebug("THE END result=%d:%s",result, err_string( result) );; return result; }
int main_v1_2( char version ) { char *function = "Tspi_TPM_SetOperatorAuth01"; TSS_HCONTEXT hContext; TSS_HTPM hTPM; TSS_HKEY hSRK; TSS_HPOLICY hOperatorPolicy; TSS_RESULT result; 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 = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_OPERATOR, &hOperatorPolicy); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Context_CreateObject", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } result = Tspi_Policy_SetSecret( hOperatorPolicy, TESTSUITE_OPERATOR_SECRET_MODE, TESTSUITE_OPERATOR_SECRET_LEN, TESTSUITE_OPERATOR_SECRET); if ( result != TSS_SUCCESS ) { print_error( "Tspi_Policy_SetSecret", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } result = Tspi_TPM_SetOperatorAuth( hTPM, hOperatorPolicy ); if ( result != TSS_SUCCESS ) { print_error( "Tspi_TPM_SetOperatorAuth", result ); print_error_exit( function, err_string(result) ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } else { print_success( function, result ); } print_end_test( function ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); }
int main(int argc, char *argv[]) { char *filename = DEFAULT_FILENAME; int i=1; char *param; TSS_RESULT result; TSS_HCONTEXT hContext; TSS_HDAA hDAA; FILE *file; // foreground = 1; // for debug printf("Key Verification (%s:%s,%s)\n", argv[0], __DATE__, __TIME__); while( i < argc) { param = argv[ i]; if( strcmp( param, "-if") == 0 || strcmp( param, "--issuer_file")) { i++; if( i == argc) return print_usage( argv[0]); filename = argv[i]; } else { fprintf(stderr, "%s:unrecognized option `%s'\n", argv[0], param); return print_usage( argv[0]); } i++; } bi_init( NULL); printf("Loading issuer info (keypair & proof) -> \'%s\'", filename); file = fopen( filename, "r"); if( file == NULL) { fprintf( stderr, "%s: Error when opening \'%s\': %s\n", argv[0], filename, strerror( errno)); return -1; } KEY_PAIR_WITH_PROOF_internal *key_pair_with_proof = load_KEY_PAIR_WITH_PROOF( file); if( key_pair_with_proof == NULL) { fprintf( stderr, "%s: Error when reading \'%s\': %s\n", argv[0], filename, strerror( errno)); return -1; } fclose( file); // Create Context printf("\nCreate Context\n"); result = Tspi_Context_Create( &hContext ); if ( result != TSS_SUCCESS ) { fprintf( stderr, "Tspi_Context_Create %d\n", result ); exit( result ); } // Connect to Context printf("\nConnect to the context\n"); result = Tspi_Context_Connect( hContext, NULL ); if ( result != TSS_SUCCESS ) { fprintf( stderr, "Tspi_Context_Connect error:%d\n", result ); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( result ); } //TODO save key in the persistent store // result = ps_write_key( fd, ) //Create Object result = obj_daa_add( hContext, &hDAA); if (result != TSS_SUCCESS) { LogError("Tspi_Context_CreateObject:%d", result); Tspi_Context_Close(hContext); LogError("issuer_setup: %s", err_string(result)); exit(result); } // TSS_HDAA, TSS_HKEY, TSS_DAA_PK_PROOF, TSS_BOOL* isCorrect( hDAA, key_pair_with_proof->pk, key_pair_with_proof->proof); obj_daa_remove( hDAA, hContext); printf("\nClosing the context\n"); Tspi_Context_FreeMemory( hContext, NULL ); Tspi_Context_Close( hContext ); exit( 0 ); }
main_v1_1(void){ char *nameOfFunction = "Tspi_GetAttribData19"; TSS_FLAG initFlags; TSS_HKEY hKey; TSS_HCONTEXT hContext; TSS_RESULT result; TSS_HKEY hSRK; BYTE* uuid; UINT32 uuidLength; int rc; TSS_UUID null_uuid, key_uuid; initFlags = TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048 | TSS_KEY_VOLATILE | TSS_KEY_NO_AUTHORIZATION | TSS_KEY_NOT_MIGRATABLE; memset(&null_uuid, 0, sizeof(TSS_UUID)); memset(&key_uuid, 0x7f, sizeof(TSS_UUID)); print_begin_test(nameOfFunction); //Create Context and connect result = connect_load_srk(&hContext, &hSRK); if (result != TSS_SUCCESS) { print_error("connect_load_srk", result); print_error_exit(nameOfFunction, err_string(result)); exit(result); } //Create Key Object result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY, initFlags, &hKey); if (result != TSS_SUCCESS) { print_error("Tspi_Context_CreateObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Create Key in the TPM result = Tspi_Key_CreateKey(hKey, hSRK, 0); if (result != TSS_SUCCESS) { print_error("Tspi_Key_CreateKey", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Call GetAttribData, uuid should be all 0's result = Tspi_GetAttribData(hKey, TSS_TSPATTRIB_KEY_UUID, 0, &uuidLength, &uuid); if (result != TSS_SUCCESS) { print_error("Tspi_GetAttribData", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Check length and data if (uuidLength != sizeof(TSS_UUID)) { print_verifyerr("uuid length from Tspi_GetAttribData", 0, 1); print_error("uuid length from Tspi_GetAttribData", TSS_E_FAIL); Tspi_Context_Close(hContext); exit(result); } if ((rc = memcmp(uuid, &null_uuid, uuidLength))) { print_verifyerr("a null uuid from Tspi_GetAttribData", 0, rc); print_hex(uuid, sizeof(TSS_UUID)); print_error("uuid NULL from Tspi_GetAttribData", TSS_E_FAIL); Tspi_Context_Close(hContext); exit(result); } Tspi_Context_FreeMemory(hContext, uuid); register_key: //Register Key result = Tspi_Context_RegisterKey(hContext, hKey, TSS_PS_TYPE_SYSTEM, key_uuid, TSS_PS_TYPE_SYSTEM, SRK_UUID); if (TSS_ERROR_CODE(result) == TSS_E_KEY_ALREADY_REGISTERED) { result = Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM, key_uuid, &hKey); if (result != TSS_SUCCESS) { print_error("Tspi_Context_UnregisterKey", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_CloseObject(hContext, hKey); Tspi_Context_Close(hContext); exit(result); } goto register_key; } else if (result != TSS_SUCCESS) { print_error("Tspi_Context_RegisterKey", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_CloseObject(hContext, hKey); Tspi_Context_Close(hContext); exit(result); } //Close the object result = Tspi_Context_CloseObject(hContext, hKey); if (result != TSS_SUCCESS) { print_error("Tspi_Context_CloseObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_CloseObject(hContext, hKey); Tspi_Context_Close(hContext); exit(result); } hKey = 0; //Load the key by UUID from PS result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM, key_uuid, &hKey); if (result != TSS_SUCCESS) { print_error("Tspi_Context_LoadKeyByUUID", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_CloseObject(hContext, hKey); Tspi_Context_Close(hContext); exit(result); } //Call GetAttribData, uuid should be equal to key_uuid result = Tspi_GetAttribData(hKey, TSS_TSPATTRIB_KEY_UUID, 0, &uuidLength, &uuid); if (result != TSS_SUCCESS) { print_error("Tspi_GetAttribData", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_Close(hContext); exit(result); } //Check length and data if (uuidLength != sizeof(TSS_UUID)) { print_verifyerr("uuid length from Tspi_GetAttribData", 0, 1); print_error("uuid length from Tspi_GetAttribData", TSS_E_FAIL); Tspi_Context_Close(hContext); exit(result); } if ((rc = memcmp(uuid, &key_uuid, uuidLength))) { print_verifyerr("key's uuid from Tspi_GetAttribData", 0, rc); print_hex((BYTE *)&key_uuid, sizeof(TSS_UUID)); print_error("key's uuid from Tspi_GetAttribData", TSS_E_FAIL); Tspi_Context_Close(hContext); exit(result); } print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_Close(hContext); exit(0); }
int main_v1_2(char version) { char *nameOfFunction = "Tspi_Nv_ReadValue03"; TSS_HCONTEXT hContext = NULL_HCONTEXT; TSS_HNVSTORE hNVStore = 0;//NULL_HNVSTORE TSS_HOBJECT hPolObject = NULL_HOBJECT; TSS_HPOLICY hPolicy = NULL_HPOLICY; TSS_HTPM hTPM = NULL_HTPM; BYTE *auth = "123456"; UINT32 auth_length = 6; BYTE *policyData; UINT32 read_space = 10; TSS_RESULT result; print_begin_test(nameOfFunction); //Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create ", result); print_error_exit(nameOfFunction, err_string(result)); exit(result); } //Connect Context result = Tspi_Context_Connect(hContext,NULL); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Create TPM NV object */ result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_NV, 0,&hNVStore); if (result != TSS_SUCCESS) { print_error("Tspi_Context_CreateObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } #ifdef NV_LOCKED /* Get TPM object */ result = Tspi_Context_GetTpmObject(hContext, &hTPM); if (result != TSS_SUCCESS) { print_error("Tspi_Context_GetTpmObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hPolicy); if (result != TSS_SUCCESS) { print_error("Tspi_GetPolicyObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set password */ 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); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } #endif /* Create policy object for the NV object*/ result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hPolObject); if (result != TSS_SUCCESS) { print_error("Tspi_Context_CreateObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set password */ result = Tspi_Policy_SetSecret(hPolObject, TSS_SECRET_MODE_PLAIN, auth_length, auth); if (result != TSS_SUCCESS) { print_error("Tspi_Policy_SetSecret", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set password */ result = Tspi_Policy_AssignToObject(hPolObject, hNVStore); if (result != TSS_SUCCESS) { print_error("Tspi_Policy_AssignToObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set the index to be defined. */ result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_INDEX, 0,0x00011143); if (result != TSS_SUCCESS) { print_error("Tspi_SetAttribUint32 for setting NV index", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set the permission for the index. */ result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_PERMISSIONS, 0, 0x42000); if (result != TSS_SUCCESS) { print_error("Tspi_SetAttribUint32 for setting permission", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set the data size to be defined. */ result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_DATASIZE, 0, 0xa); if (result != TSS_SUCCESS) { print_error("Tspi_SetAttribUint32 for setting data size", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /*Define NV space*/ result = Tspi_NV_DefineSpace(hNVStore, 0, 0); //Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Create ", result); print_error_exit(nameOfFunction, err_string(result)); exit(result); } //Connect Context result = Tspi_Context_Connect(hContext,NULL); if (result != TSS_SUCCESS) { print_error("Tspi_Context_Connect", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Create TPM NV object */ result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_NV, 0,&hNVStore); if (result != TSS_SUCCESS) { print_error("Tspi_Context_CreateObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Create policy object for the NV object*/ result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hPolObject); if (result != TSS_SUCCESS) { print_error("Tspi_Context_CreateObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set password */ result = Tspi_Policy_SetSecret(hPolObject, TSS_SECRET_MODE_PLAIN, auth_length, auth); if (result != TSS_SUCCESS) { print_error("Tspi_Policy_SetSecret", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set password */ result = Tspi_Policy_AssignToObject(hPolObject, hNVStore); if (result != TSS_SUCCESS) { print_error("Tspi_Policy_AssignToObject", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } /* Set the index to be defined. */ result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_INDEX, 0,0x00011143); if (result != TSS_SUCCESS) { print_error("Tspi_SetAttribUint32 for setting NV index", result); print_error_exit(nameOfFunction, err_string(result)); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } result = Tspi_NV_ReadValue(hNVStore,/*read_offset*/0, &read_space, &policyData); #ifdef CLEAR_TEST_INDEX Tspi_Context_GetTpmObject(hContext, &hTPM); Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hPolicy); Tspi_Policy_SetSecret(hPolicy, TESTSUITE_OWNER_SECRET_MODE, TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET); Tspi_NV_ReleaseSpace(hNVStore); #endif #ifdef NV_LOCKED if (TSS_ERROR_CODE(result)== TSS_SUCCESS) { print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(0); } else { print_error("Tspi_NV_ReadValue", result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } #else if (TSS_ERROR_CODE(result)== TSS_SUCCESS) { print_success(nameOfFunction, result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(0); } else { print_error("Tspi_NV_ReadValue", result); print_end_test(nameOfFunction); Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } #endif }