|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
30 void show_hmac_debug(
unsigned char* hex,
unsigned int length,
const std::string& context)
33 int off = context.length();
34 buf =
new char[length * 3 + off + 2];
35 strcpy(buf, context.c_str());
36 for (
unsigned int i = 0; i < length; i++) {
37 sprintf(&(buf[off + i * 3]),
"%X ", hex[i]);
47 authentication_enabled(false)
50 static bool auth_warning_shown =
false;
51 if (auth_warning_shown) {
62 fname = rf.
findFile(
"auth.conf", opt);
67 yCDebug(AUTHHMAC,
"Cannot find auth.conf file. Authentication disabled.\n");
68 auth_warning_shown =
true;
77 yCWarning(AUTHHMAC,
"No \"AUTH\" group found in auth.conf file. Authentication disabled.\n");
78 auth_warning_shown =
true;
83 if (!(key.length() > 0)) {
84 yCWarning(AUTHHMAC,
"No \"key\" found in \"AUTH\" group in auth.conf file. Authentication disabled.\n");
85 auth_warning_shown =
true;
89 size_t key_len = key.length();
90 auto* tmp =
new unsigned char[key_len];
91 strcpy(
reinterpret_cast<char*
>(tmp), key.c_str());
92 HMAC_INIT(&context, tmp,
static_cast<unsigned int>(key_len));
94 srand(
static_cast<unsigned>(time(
nullptr)));
96 if (!authentication_enabled) {
97 yCInfo(AUTHHMAC,
"Authentication enabled.\n");
98 authentication_enabled =
true;
106 if (!authentication_enabled) {
130 if (!send_hmac(streamOut, nonce1, mac)) {
137 if (!receive_hmac(streamIn, nonce2, mac)) {
145 if (!check_hmac(mac, mac_check)) {
160 return send_hmac(streamOut, nonce3, mac);
165 if (!authentication_enabled) {
185 if (!receive_hmac(streamIn, nonce1, mac)) {
191 if (!check_hmac(mac, mac_check)) {
203 if (!send_hmac(streamOut, nonce2, mac)) {
211 if (!receive_hmac(streamIn, nonce3, mac)) {
219 if (!check_hmac(mac, mac_check)) {
228 bool AuthHMAC::send_hmac(
OutputStream* stream,
unsigned char* nonce,
unsigned char* mac)
232 stream->
write(nonce_bytes);
233 stream->
write(mac_bytes);
238 return stream->
isOk();
241 bool AuthHMAC::receive_hmac(
InputStream* stream,
unsigned char* nonce,
unsigned char* mac)
245 stream->
read(nonce_bytes);
246 stream->
read(mac_bytes);
251 return stream->
isOk();
254 bool AuthHMAC::check_hmac(
unsigned char* mac,
unsigned char* mac_check)
258 std::string check =
"digest check ";
260 check +=
"successful";
270 void AuthHMAC::fill_nonce(
unsigned char* nonce)
272 std::random_device rd;
273 std::mt19937 mt(rd());
274 std::uniform_int_distribution<int> dist(0, 255);
275 for (
unsigned int i = 0; i <
NONCE_LEN; i++) {
276 nonce[i] =
static_cast<unsigned char>(dist(mt));
A simple collection of objects that can be described and transmitted in a portable way.
#define yCWarning(component,...)
static void lock()
Call wait() on a global mutual-exclusion semaphore allocated by YARP.
virtual void write(char ch)
Write a single byte to the stream.
These options are loosely based on http://wiki.icub.org/wiki/YARP_ResourceFinder.
Simple specification of the minimum functions needed from output streams.
void show_hmac_debug(unsigned char *hex, unsigned int length, const std::string &context)
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
bool authSource(yarp::os::InputStream *streamIn, yarp::os::OutputStream *streamOut)
std::string findFile(const std::string &name)
Find the full path to a file.
virtual std::string asString() const
Get string value.
MessageFilter messageFilter
A simple abstraction for a block of bytes.
bool isNull() const override
Checks if the object is invalid.
static ResourceFinder & getResourceFinderSingleton()
Access a ResourceFinder singleton whose lifetime will match that of the YARP library.
virtual bool isOk() const =0
Check if the stream is ok or in an error state.
bool fromConfigFile(const std::string &fname, bool wipe=true)
Interprets a file as a list of properties.
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
static void unlock()
Call post() on a global mutual-exclusion semaphore allocated by YARP.
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
bool authDest(yarp::os::InputStream *streamIn, yarp::os::OutputStream *streamOut)
#define YARP_OS_LOG_COMPONENT(name, name_string)
The components from which ports and connections are built.
A class for storing options and configuration information.
Helper class for finding config files and other external resources.