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);


}
예제 #2
0
// client connection callback
void ReasonerCommunication::connectionErrorCB(ServiceClient & client, CommunicationError error){
	// remove currently pending messages
	client.dropPendingMessages();
	sleep(1);
	// try to reconnect periodically
	client.ireconnect();
}
예제 #3
0
    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");
        }
    }
예제 #4
0
    NodeID pickNextNodeID() const
    {
        // We can't do index search because indices are unstable in Map<>
        // First try - from the current node up
        NextNodeIDSearchPredicate s1(*this);
        (void)pending_nodes_.find<NextNodeIDSearchPredicate&>(s1);

        if (s1.output != NextNodeIDSearchPredicate::DefaultOutput)
        {
            last_queried_node_id_ = s1.output;
        }
        else if (last_queried_node_id_ != 0)
        {
            // Nothing was found, resetting the selector and trying again
            UAVCAN_TRACE("FirmwareUpdateTrigger", "Node selector reset, last value: %d", int(last_queried_node_id_));
            last_queried_node_id_ = 0;

            NextNodeIDSearchPredicate s2(*this);
            (void)pending_nodes_.find<NextNodeIDSearchPredicate&>(s2);

            if (s2.output != NextNodeIDSearchPredicate::DefaultOutput)
            {
                last_queried_node_id_ = s2.output;
            }
        }
        else
        {
            ; // Hopeless
        }
        UAVCAN_TRACE("FirmwareUpdateTrigger", "Next node ID to query: %d, pending nodes: %u, pending calls: %u",
                     int(last_queried_node_id_), pending_nodes_.getSize(),
                     begin_fw_update_client_.getNumPendingCalls());
        return last_queried_node_id_;
    }
예제 #5
0
    NodeID pickNextNodeToQuery(bool& out_at_least_one_request_needed) const
    {
        out_at_least_one_request_needed = false;

        for (unsigned iter_cnt_ = 0; iter_cnt_ < (sizeof(entries_) / sizeof(entries_[0])); iter_cnt_++) // Round-robin
        {
            last_picked_node_++;
            if (last_picked_node_ > NodeID::Max)
            {
                last_picked_node_ = 1;
            }
            UAVCAN_ASSERT((last_picked_node_ >= 1) &&
                          (last_picked_node_ <= NodeID::Max));

            const Entry& entry = getEntry(last_picked_node_);

            if (entry.request_needed)
            {
                out_at_least_one_request_needed = true;

                if (entry.updated_since_last_attempt &&
                    !get_node_info_client_.hasPendingCallToServer(last_picked_node_))
                {
                    UAVCAN_TRACE("NodeInfoRetriever", "Next node to query: %d", int(last_picked_node_));
                    return NodeID(last_picked_node_);
                }
            }
        }

        return NodeID();        // No node could be found
    }
예제 #6
0
TopologyType NetworkForwarderTopology::lookupTypeByName( const string& name ) throw() {

    NetworkForwarderRequestMessage mess;
    mess.request_type = NETWORK_FORWARDER_TOPOLOGY_TYPE_REGISTER;
    mess.id = 0;
    mess.name = "";

    BlockingRPCMessage container;
    {
        unique_lock<mutex> lock(container.m);
        client->isend(& mess, & container);

        printf("1");
        fflush(stdout);

        // wait for the response
        container.cv.wait(lock);

        printf("10");
        fflush(stdout);

    }

    TopologyType returnType;
    Release<TopologyTypeImplementation> newType(new TopologyTypeImplementation(name, (size_t) container.response.id));
    returnType.setObject(newType);

    return returnType;
}
예제 #7
0
    int init()
    {
        int res = get_node_info_client_.init();
        if (res < 0)
        {
            return res;
        }
        get_node_info_client_.setCallback(
            GetNodeInfoResponseCallback(this, &NodeDiscoverer::handleGetNodeInfoResponse));

        res = node_status_sub_.start(NodeStatusCallback(this, &NodeDiscoverer::handleNodeStatus));
        if (res < 0)
        {
            return res;
        }

        // Note: the timer starts ad-hoc from the node status callback, not here.

        return 0;
    }
예제 #8
0
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;

}
예제 #9
0
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;
}
예제 #10
0
    /**
     * Starts the object. Once started, it can't be stopped unless destroyed.
     *
     * @param node_info_retriever       The object will register itself against this retriever.
     *                                  When the destructor is called, the object will unregister itself.
     *
     * @param common_path_prefix        If set, this path will be prefixed to all firmware pathes provided by the
     *                                  application interface. The prefix does not need to end with path separator;
     *                                  the last trailing one will be removed (so use '//' if you need '/').
     *                                  By default the prefix is empty.
     *
     * @return                          Negative error code.
     */
    int start(NodeInfoRetriever& node_info_retriever,
              const FirmwareFilePath& arg_common_path_prefix = FirmwareFilePath(),
              const TransferPriority priority = TransferPriority::OneHigherThanLowest)
    {
        /*
         * Configuring the node info retriever
         */
        node_info_retriever_ = &node_info_retriever;

        int res = node_info_retriever_->addListener(this);
        if (res < 0)
        {
            return res;
        }

        /*
         * Initializing the prefix, removing only the last trailing path separator.
         */
        common_path_prefix_ = arg_common_path_prefix;

        if (!common_path_prefix_.empty() &&
            *(common_path_prefix_.end() - 1) == protocol::file::Path::SEPARATOR)
        {
            common_path_prefix_.resize(uint8_t(common_path_prefix_.size() - 1U));
        }

        /*
         * Initializing the client
         */
        res = begin_fw_update_client_.init(priority);
        if (res < 0)
        {
            return res;
        }
        begin_fw_update_client_.setCallback(
            BeginFirmwareUpdateResponseCallback(this, &FirmwareUpdateTrigger::handleBeginFirmwareUpdateResponse));

        // The timer will be started ad-hoc
        return 0;
    }
예제 #11
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");
            }
        }
    }
예제 #12
0
    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");
        }
    }
예제 #13
0
TopologyType NetworkForwarderTopology::lookupTypeById( TopologyTypeId anId ) throw() {

    NetworkForwarderRequestMessage mess;
    mess.type = NETWORK_FORWARDER_TOPOLOGY_TYPE_LOOKUP_BY_ID;
    mess.id = anId;
    mess.name = "";

    BlockingRPCMessage container;
    {
        unique_lock<mutex> lock(container.m);
        client->isend(& mess, & container);

        // wait for the response
        container.cv.wait(lock);
    }

    TopologyType returnType;
    Release<TopologyTypeImplementation> newType(new TopologyTypeImplementation( container.response.name, anId));
    returnType.setObject(newType);

    return returnType;
}
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);
}
예제 #15
0
 /*
  * Own methods
  */
 INode& getNode() { return begin_fw_update_client_.getNode(); }
예제 #16
0
 int call(uavcan::NodeID node_id, const typename DataType::Request& request)
 {
     client.setCallback(collector.bind());
     return client.call(node_id, request);
 }