def test_func(param_str): filepath = './features/0_2_person1/13.2.52.txt' filepath0 = './features/0_2_person1/13.4.53.txt' addr_list = './addr_list.json' param_args = param_str.split(',') index_id = param_args[0] node_name = param_args[1] node_address = SrvAPI.getAddress(node_name, addr_list) # construct data argument #data_args = {} #data_args ['host_address'] = node_address #data_args ['url_rule'] = '/BlendCAC/api/v1.0/getCapToken' start_time = time.time() print(SrvAPI.getIndexToken(index_id)) print(SrvAPI.getAuthorizedNodes()) print(SrvAPI.verify_indexToken(index_id, filepath)) print(SrvAPI.getCapToken(node_address)) #print(SrvAPI.isValidAccess(req_args)) end_time = time.time() #calculate exec time exec_time = end_time - start_time time_exec = format(exec_time * 1000, '.3f') print("Execution time is:%2.6f" % (exec_time)) FileUtil.AddLine('exec_time_client.log', time_exec)
def test_ServiceAccess(host_ip): # set host id address filepath = './features/0_2_person1/13.2.52.txt' filepath0 = './features/6_10_person/14.52.38.txt' addr_list = '../../node_data/addr_list.json' project_id = 1 index_id = 1 node_name = 'Desk_PI_Plus_Sam1' node_address = SrvAPI.getAddress(node_name, addr_list) # construct data argument data_args = {} data_args['project_id'] = project_id data_args['host_ip'] = host_ip data_args['index_id'] = index_id data_args['filepath'] = filepath data_args['host_address'] = node_address data_args['url_rule'] = '/BlendCAC/api/v1.0/getCapToken' # set project id project_id = 3 start_time = time.time() #------------------ test data access service API ------------------ test_search(data_args) end_time = time.time() exec_time = end_time - start_time time_exec = format(exec_time * 1000, '.3f') print("Execution time is:%2.6f" % (exec_time)) FileUtil.AddLine('exec_time_client.log', time_exec)
def is_valid_access_request(req_args): #Get account address accountAddr = RBACToken.getAddress( 'sam_miner_win7_0', '../CapbilityToken/test/addr_list.json') #Define ls_time_exec to save executing time to log ls_time_exec = [] #get token data start_time = time.time() # 1) get token from smart contract, high overload token_data = RBACPolicy.get_token(accountAddr) # 2) Save token data to local token.dat #FileUtil.AddLine('RBAC_token.dat', TypesUtil.json_to_string(token_data)) # 3) read token from local data, low overload '''read_token=FileUtil.ReadLines('RBAC_token.dat') token_data=TypesUtil.string_to_json(read_token[0])''' #print(token_data) exec_time = time.time() - start_time ls_time_exec.append(format(exec_time * 1000, '.3f')) print("Execution time of get_token is:%2.6f" % (exec_time)) #extract access action from request access_data = {} access_data['url_rule'] = req_args.url_rule access_data['method'] = req_args.method #print(access_data) start_time = time.time() if (not RBACPolicy.is_token_valid(token_data)): print('token valid fail') return False exec_time = time.time() - start_time ls_time_exec.append(format(exec_time * 1000, '.3f')) print("Execution time of is_token_valid is:%2.6f" % (exec_time)) start_time = time.time() if (not RBACPolicy.is_access_valid(token_data, access_data)): print('access valid fail') return False exec_time = time.time() - start_time ls_time_exec.append(format(exec_time * 1000, '.3f')) print("Execution time of is_access_valid is:%2.6f" % (exec_time)) #transfer list to string str_time_exec = " ".join(ls_time_exec) #print(str_time_exec) FileUtil.AddLine('exec_time_server.log', str_time_exec) return True
def verify_indexToken(str_index, filepath): # Define ls_time_exec to save executing time to log ls_time_exec=[] # mark the start time start_time=time.time() #1) read index data in contract token_data=mytoken.getIndexToken(str_index); #print(token_data) # calculate computational cost exec_time=time.time()-start_time ls_time_exec.append(format(exec_time*1000, '.3f')) print("Execution time of getIndexToken is:%2.6f" %(exec_time)) # mark the start time start_time=time.time() #2) extract data from index file indexData=IndexPolicy.ExtractData(filepath) str_value=str(indexData) # calculate computational cost exec_time=time.time()-start_time ls_time_exec.append(format(exec_time*1000, '.3f')) print("Execution time of extract Index is:%2.6f" %(exec_time)) # mark the start time start_time=time.time() #3) calculate hash value of str_value # transfer string data to bytes block bytes_block = TypesUtil.string_to_bytes(str_value); hash_value = Crypto_Hash.generate_hash(bytes_block) # compare ret_indexAuth = (str(hash_value)==token_data[1]) # calculate computational cost exec_time=time.time()-start_time ls_time_exec.append(format(exec_time*1000, '.3f')) print("Execution time of verifyIndex is:%2.6f" %(exec_time)) #transfer list to string str_time_exec=" ".join(ls_time_exec) #print(str_time_exec) FileUtil.AddLine('exec_time_authIndex.log', str_time_exec) #return index authentication result return ret_indexAuth
def test_func(host_ip, index_id): filepath = './features/0_2_person1/13.2.52.txt' filepath0 = './features/0_2_person1/13.4.53.txt' start_time = time.time() print(WSClient.getIndexToken(host_ip, index_id)) print(WSClient.getAuthorizedNodes(host_ip)) print(WSClient.verify_indexToken(host_ip, index_id, filepath)) end_time = time.time() #calculate exec time exec_time = end_time - start_time time_exec = format(exec_time * 1000, '.3f') print("Execution time is:%2.6f" % (exec_time)) FileUtil.AddLine('exec_time_client.log', time_exec)
def test_CapAC(): #params = {'project_id':'2'} data_args = {'project_id': '2'} start_time = time.time() #print token_data #test_add(data_args) #test_update(data_args) #test_delete(data_args) test_search(data_args) end_time = time.time() exec_time = end_time - start_time time_exec = format(exec_time * 1000, '.3f') print("Execution time is:%2.6f" % (exec_time)) FileUtil.AddLine('exec_time_client.log', time_exec) '''print WSClient.Get_Datasets('http://128.226.78.217/test/api/v1.0/dt', data_args)
def test_func(host_ip, node_name): addr_list = '../../node_data/addr_list.json' node_address = WSClient.getAddress(node_name, addr_list) # construct data argument data_args = {} data_args['host_ip'] = host_ip data_args['host_address'] = node_address data_args['url_rule'] = '/BlendCAC/api/v1.0/getCapToken' start_time = time.time() print(WSClient.getCapToken(data_args)) print(WSClient.isValidAccess(data_args)) end_time = time.time() #calculate exec time exec_time = end_time - start_time time_exec = format(exec_time * 1000, '.3f') print("Execution time is:%2.6f" % (exec_time)) FileUtil.AddLine('exec_time_client.log', time_exec)
def is_valid_access_request(req_args): #Get account address addr_client = req_args.json['host_address'] url_rule = req_args.json['url_rule'] #Define ls_time_exec to save executing time to log ls_time_exec = [] # define branch control flag query_src = 0 # smart contract:0, local cache:1 is_cachetoken = 0 # cache data:1, not cache data:0 #get token data start_time = time.time() if (query_src == 0): # ----------a) query token from smart contract ------------ token_data = CapPolicy.get_token(addr_client) #print(token_data) if (is_cachetoken == 1): # 2) Save token data to local token.dat FileUtil.AddLine('ACtoken.dat', TypesUtil.json_to_string(token_data)) else: # ----------b) read authToken from local cached file ------------ read_token = FileUtil.ReadLines('ACtoken.dat') token_data = TypesUtil.string_to_json(read_token[0]) #print(token_data) exec_time = time.time() - start_time ls_time_exec.append(format(exec_time * 1000, '.3f')) print("Execution time of get_token is:%2.6f" % (exec_time)) #extract access action from request access_data = {} access_data['url_rule'] = url_rule access_data['method'] = req_args.method #print(access_data) start_time = time.time() if (not CapPolicy.is_token_valid(token_data)): print('token valid fail') return False exec_time = time.time() - start_time ls_time_exec.append(format(exec_time * 1000, '.3f')) print("Execution time of is_token_valid is:%2.6f" % (exec_time)) start_time = time.time() if (not CapPolicy.is_access_valid(token_data, access_data)): print('access valid fail') return False exec_time = time.time() - start_time ls_time_exec.append(format(exec_time * 1000, '.3f')) print("Execution time of is_access_valid is:%2.6f" % (exec_time)) #transfer list to string str_time_exec = " ".join(ls_time_exec) #print(str_time_exec) FileUtil.AddLine('capac_exec_time_server.log', str_time_exec) return True
def verify_AuthToken(req_args): # extract client address from req_args #addr_client = req_args['host_address'] addr_client = req_args.json['host_address'] #print(addr_client) # Define ls_time_exec to save executing time to log ls_time_exec = [] # define branch control flag query_src = 0 # smart contract:0, local cache:1 is_cachetoken = 0 # cache data:1, not cache data:0 # mark the start time start_time = time.time() if (query_src == 0): # ----------a) query token from smart contract ------------ # 1) get host Vnode data in contract accounts = myAuthToken.getAccounts() json_VNode_host = AuthPolicy.get_VNodeInfo(accounts[0]) #2) get client Vnode in contract json_VNode_client = AuthPolicy.get_VNodeInfo(addr_client) #print(json_VNode_host) #print(json_VNode_client) if (is_cachetoken == 1): json_authToken = {} json_authToken['host'] = json_VNode_host json_authToken['client'] = json_VNode_client #print(json_authToken) # 2) Save token data to local token.dat FileUtil.AddLine('authToken.dat', TypesUtil.json_to_string(json_authToken)) else: # ----------b) read authToken from local cached file ------------ # 3) read token from local data, low overload read_token = FileUtil.ReadLines('authToken.dat') token_data = TypesUtil.string_to_json(read_token[0]) json_VNode_host = token_data['host'] json_VNode_client = token_data['client'] print("localhost: %s | client: %s" % (json_VNode_host, json_VNode_client)) #3) authicate identity based on token # compare ret_indexAuth = ( json_VNode_host['VZoneID'] == json_VNode_client['VZoneID']) # calculate computational cost exec_time = time.time() - start_time ls_time_exec.append(format(exec_time * 1000, '.3f')) print("Execution time of %s authentication is:%2.6f" % (addr_client, exec_time)) #transfer list to string str_time_exec = " ".join(ls_time_exec) #print(str_time_exec) FileUtil.AddLine('auth_exec_time_server.log', str_time_exec) #return index authentication result return ret_indexAuth