15 #include <openssl/sha.h> 17 #include <rosauth/Authentication.h> 29 #define SECRET_FILE_PARAM "/ros_mac_authentication/secret_file_location" 35 #define MISSING_PARAMETER -1 41 #define FILE_IO_ERROR -2 47 #define INVALID_SECRET -3 53 #define SECRET_LENGTH 16 58 bool authenticate(rosauth::Authentication::Request &req, rosauth::Authentication::Response &res)
68 bool time_check = diff->
sec < 5 && req.end > t;
76 ss <<
secret << req.client << req.dest << req.rand << req.t.sec << req.level << req.end.sec;
77 string local_hash = ss.str();
80 unsigned char sha512_hash[SHA512_DIGEST_LENGTH];
81 SHA512((
unsigned char *)local_hash.c_str(), local_hash.length(), sha512_hash);
84 char hex[SHA512_DIGEST_LENGTH * 2];
85 for (
int i = 0; i < SHA512_DIGEST_LENGTH; i++)
86 sprintf(&hex[i * 2],
"%02x", sha512_hash[i]);
89 res.authenticated = (strcmp(hex, req.mac.c_str()) == 0);
92 res.authenticated =
false;
104 int main(
int argc,
char **argv)
107 init(argc, argv,
"ros_mac_authentication");
121 f.open(file.c_str(), ifstream::in);
136 ROS_INFO(
"ROS Authentication Server Started");
144 ROS_ERROR(
"Could not read from file '%s'", file.c_str());
void init(const M_string &remappings)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
#define MISSING_PARAMETER
bool getParam(const std::string &key, std::string &s) const
int main(int argc, char **argv)
bool authenticate(rosauth::Authentication::Request &req, rosauth::Authentication::Response &res)
#define SECRET_FILE_PARAM