TEST(RosHashAuthentication, validAuthentication) { string msg = "bc8c629cd7477fd580b8f9e8da49e5aad364b769192.168.1.101192.168.1.1111337"; string sign = "5a436753ef5b30b77951707b893c65343129c51d79d0a67bb746830ee7d6412bfd730c46b5b9be3a4651f542a163c7b7a38b711bea6e16f3cc4bc478c382f301"; string addr = "a28779d29c49fd57d0fc4130e5ebec07c2c79ef5"; // make the request rosauth::Authentication srv; srv.request.msg = msg; srv.request.sign = sign; srv.request.addr = addr; EXPECT_TRUE(client.call(srv)); EXPECT_TRUE(srv.response.authenticated); string msg1 = "bc8c629cd7477fd580b8f9e8da49e5aad364b769192.168.1.101192.168.1.1111337"; string sign1 = "ff436753ef5b30b77951707b893c65343129c51d79d0a67bb746830ee7d6412bfd730c46b5b9be3a4651f542a163c7b7a38b711bea6e16f3cc4bc478c382f301"; string addr1 = "a28779d29c49fd57d0fc4130e5ebec07c2c79ef5"; // make the request rosauth::Authentication srv1; srv1.request.msg = msg1; srv1.request.sign = sign1; srv1.request.addr = addr1; EXPECT_TRUE(client.call(srv1)); EXPECT_FALSE(srv1.response.authenticated); }
void handleTimerEvent(const TimerEvent&) { if (get_node_info_client_.hasPendingCalls()) { return; } const NodeID node_id = pickNextNodeToQueryAndCleanupMap(); if (!node_id.isUnicast()) { trace(TraceDiscoveryTimerStop, 0); stop(); return; } if (!handler_.canDiscoverNewNodes()) { return; // Timer must continue to run in order to not stuck when it unlocks } trace(TraceDiscoveryGetNodeInfoRequest, node_id.get()); UAVCAN_TRACE("dynamic_node_id_server::NodeDiscoverer", "Requesting GetNodeInfo from node %d", int(node_id.get())); const int res = get_node_info_client_.call(node_id, protocol::GetNodeInfo::Request()); if (res < 0) { getNode().registerInternalFailure("NodeDiscoverer GetNodeInfo call"); } }
void OpenSimulatedDoor::run() { NodeHandle n; if (!requestSent) { ServiceClient doorClient = n.serviceClient<bwi_msgs::DoorHandlerInterface> ("/update_doors"); doorClient.waitForExistence(); bwi_msgs::DoorHandlerInterface dhi; dhi.request.all_doors = false; dhi.request.door = door; dhi.request.open = true; doorClient.call(dhi); requestSent = true; } vector<string> params; params.push_back(door); LogicalNavigation senseDoor("sensedoor",params); senseDoor.run(); ros::ServiceClient currentClient = n.serviceClient<bwi_kr_execution::CurrentStateQuery> ("current_state_query"); bwi_kr_execution::AspFluent openFluent; openFluent.name = "open"; openFluent.timeStep = 0; openFluent.variables.push_back(door); bwi_kr_execution::AspRule rule; rule.head.push_back(openFluent); bwi_kr_execution::CurrentStateQuery csq; csq.request.query.push_back(rule); currentClient.call(csq); done = csq.response.answer.satisfied; }
virtual void handleTimerEvent(const TimerEvent&) { if (pending_nodes_.isEmpty()) { TimerBase::stop(); UAVCAN_TRACE("FirmwareUpdateTrigger", "Timer stopped"); return; } const NodeID node_id = pickNextNodeID(); if (!node_id.isUnicast()) { return; } FirmwareFilePath* const path = pending_nodes_.access(node_id); if (path == UAVCAN_NULLPTR) { UAVCAN_ASSERT(0); // pickNextNodeID() returned a node ID that is not present in the map return; } protocol::file::BeginFirmwareUpdate::Request req; req.source_node_id = getNode().getNodeID().get(); if (!common_path_prefix_.empty()) { req.image_file_remote_path.path += common_path_prefix_.c_str(); req.image_file_remote_path.path.push_back(protocol::file::Path::SEPARATOR); } req.image_file_remote_path.path += path->c_str(); UAVCAN_TRACE("FirmwareUpdateTrigger", "Request to %d with path: %s", int(node_id.get()), req.image_file_remote_path.path.c_str()); const int call_res = begin_fw_update_client_.call(node_id, req); if (call_res < 0) { getNode().registerInternalFailure("FirmwareUpdateTrigger call"); } }
int main(int argc, char **argv) { init(argc, argv, "add_two_ints_client"); if(argc != 3) { ROS_INFO("usage: add_two_ints_client X Y"); return 1; } NodeHandle n; ServiceClient client = n.serviceClient<beginner_tutorials::AddTwoInts>("add_two_ints"); beginner_tutorials::AddTwoInts srv; srv.request.a = atoll(argv[1]); srv.request.b = atoll(argv[2]); if (client.call(srv)) { //this line call the servie ROS_INFO("Sum: %ld", (long int)srv.response.sum); } else { ROS_ERROR("Failed to call service add_two_ints"); return 1; } return 0; }
virtual void handleTimerEvent(const TimerEvent&) { bool at_least_one_request_needed = false; const NodeID next = pickNextNodeToQuery(at_least_one_request_needed); if (next.isUnicast()) { UAVCAN_ASSERT(at_least_one_request_needed); getEntry(next).updated_since_last_attempt = false; const int res = get_node_info_client_.call(next, protocol::GetNodeInfo::Request()); if (res < 0) { get_node_info_client_.getNode().registerInternalFailure("NodeInfoRetriever GetNodeInfo call"); } } else { if (!at_least_one_request_needed) { TimerBase::stop(); UAVCAN_TRACE("NodeInfoRetriever", "Timer stopped"); } } }
TEST(RosHashAuthentication, validAuthentication) { string secret = "abcdefghijklmnop"; string client_ip = "192.168.1.101"; string dest_ip = "192.168.1.111"; string rand = "xyzabc"; Time now = Time::now(); string user_level = "admin"; Time end = Time::now(); end.sec += 120; // create the string to hash stringstream ss; ss << secret << client_ip << dest_ip << rand << now.sec << user_level << end.sec; string local_hash = ss.str(); unsigned char sha512_hash[SHA512_DIGEST_LENGTH]; SHA512((unsigned char *)local_hash.c_str(), local_hash.length(), sha512_hash); // convert to a hex string to compare char hex[SHA512_DIGEST_LENGTH * 2]; for (int i = 0; i < SHA512_DIGEST_LENGTH; i++) sprintf(&hex[i * 2], "%02x", sha512_hash[i]); // make the request rosauth::Authentication srv; srv.request.mac = string(hex); srv.request.client = client_ip; srv.request.dest = dest_ip; srv.request.rand = rand; srv.request.t = now; srv.request.level = user_level; srv.request.end = end; EXPECT_TRUE(client.call(srv)); EXPECT_TRUE(srv.response.authenticated); }
int call(uavcan::NodeID node_id, const typename DataType::Request& request) { client.setCallback(collector.bind()); return client.call(node_id, request); }