Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add security logging base class #1

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
435b0e4
add basic seclog classes as per dds-spec
artivis Feb 4, 2020
0e57b71
integrate logging to SecurityPluginFactory
artivis Feb 5, 2020
6f46fb9
add missing function definition
artivis Feb 5, 2020
3d902f0
add missing logic piece
artivis Feb 6, 2020
4016a45
typo
artivis Feb 6, 2020
dae5e75
add first seclog utest
artivis Feb 6, 2020
4749c9a
return if invalid log file path
artivis Feb 6, 2020
a93a5be
Logging members private & getters
artivis Feb 6, 2020
5b5f614
add set/get logger to security plugin base classes
artivis Feb 11, 2020
a8a391b
note
artivis Feb 11, 2020
3f8e054
add string_to_EventLogLevel
artivis Feb 13, 2020
1b64b11
logging integration to SecurityManager
artivis Feb 13, 2020
85507b8
add BuiltinLogging skeleton
artivis Feb 20, 2020
22cb93e
security factory create BuiltinLogging
artivis Feb 20, 2020
d4ac406
use BuiltinLogging in unit test
artivis Feb 20, 2020
171f159
change logger access in plugin bases
artivis Feb 25, 2020
017b0a3
make Logging::log const
artivis Feb 25, 2020
3af0b94
ConcurrentQueue final, fix type
artivis Feb 25, 2020
f9367d5
SecurityManager logInfo->logError
artivis Feb 25, 2020
4a9b5c4
rm inlines
artivis Feb 25, 2020
c701936
make Logging::publisher private
artivis Feb 25, 2020
a9156d5
mv BuiltinLogging -> LogTopic
artivis Feb 26, 2020
c83fd75
mv convert to base class
artivis Mar 20, 2020
c3b4c34
temporarily use EventLogLevel instead of LoggingLevel
artivis Mar 20, 2020
d585044
fix properties namespacing
artivis Mar 20, 2020
b0cdbbf
add guid & domaine id
artivis Mar 23, 2020
928ae4e
fix typo
artivis Mar 23, 2020
f57336b
add enable_logging_impl to config derived
artivis Mar 26, 2020
e7c719e
add compose_header
artivis Mar 26, 2020
406a549
cleanup and bugfix
artivis Mar 26, 2020
00def09
add initial logging to file
artivis Mar 26, 2020
4f5a801
log stamp full precision
artivis Mar 27, 2020
9bc52d7
use LoggingLevel as per sec 9.6
artivis Mar 27, 2020
aafbba0
rm EventLogLevel
artivis Mar 31, 2020
e462f19
distribute defaults to false & cleanup
artivis Mar 31, 2020
797e939
cleanup
artivis Mar 31, 2020
6bd8fc4
exception as arg
artivis Apr 1, 2020
bc3563d
add SECURITY_LOGGING macros
artivis Apr 2, 2020
230f8c8
first use of security logging macro
artivis Apr 2, 2020
e36e29c
logging header cosmetic
artivis Apr 2, 2020
a614f51
cleanup
artivis Apr 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/fastdds/rtps/security/accesscontrol/AccessControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Authentication;
class SecurityException;
struct ParticipantSecurityAttributes;
struct EndpointSecurityAttributes;
class Logging;

class AccessControl
{
Expand Down Expand Up @@ -152,6 +153,14 @@ class AccessControl
const std::vector<std::string>& partitions,
EndpointSecurityAttributes& attributes,
SecurityException& exception) = 0;

virtual inline bool set_logger(Logging* logger, SecurityException& /*exception*/) { logger_ = logger; return true; }
artivis marked this conversation as resolved.
Show resolved Hide resolved

virtual inline Logging* get_logger() { return logger_; }

protected:

Logging* logger_ = nullptr;
artivis marked this conversation as resolved.
Show resolved Hide resolved
};

} //namespace security
Expand Down
9 changes: 9 additions & 0 deletions include/fastdds/rtps/security/authentication/Authentication.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace fastrtps {
namespace rtps {
namespace security {

class Logging;

enum ValidationResult_t : uint32_t
{
VALIDATION_OK = 0,
Expand Down Expand Up @@ -225,6 +227,13 @@ class Authentication
virtual bool return_authenticated_peer_credential_token(PermissionsCredentialToken* token,
SecurityException& ex) = 0;

virtual inline bool set_logger(Logging* logger, SecurityException& /*exception*/) { logger_ = logger; return true; }

virtual inline Logging* get_logger() { return logger_; }

protected:

Logging* logger_ = nullptr;
};

} //namespace security
Expand Down
10 changes: 9 additions & 1 deletion include/fastdds/rtps/security/cryptography/Cryptography.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ namespace fastrtps {
namespace rtps {
namespace security {

class Logging;

class Cryptography
{
public:

Cryptography(): m_cryptokeyexchange(nullptr), m_cryptokeyfactory(nullptr),
m_cryptotransform(nullptr) {}
m_cryptotransform(nullptr), m_logger(nullptr) {}

virtual ~Cryptography() {}

Expand All @@ -44,11 +46,17 @@ class Cryptography

CryptoTransform* cryptotransform() { return m_cryptotransform; }

virtual inline bool set_logger(Logging* logger, SecurityException& /*exception*/) { m_logger = logger; return true; }

virtual inline Logging* get_logger() { return m_logger; }

protected:

CryptoKeyExchange *m_cryptokeyexchange;
CryptoKeyFactory *m_cryptokeyfactory;
CryptoTransform *m_cryptotransform;

Logging *m_logger;
kyrofa marked this conversation as resolved.
Show resolved Hide resolved
};

} //namespace security
Expand Down
79 changes: 79 additions & 0 deletions include/fastdds/rtps/security/logging/BuiltinLogging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2020 Canonical ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
* @file Logging.h
*/
#ifndef _FASTDDS_RTPS_SECURITY_LOGGING_BUILTINLOGGING_H_
#define _FASTDDS_RTPS_SECURITY_LOGGING_BUILTINLOGGING_H_

#include "fastdds/rtps/security/logging/Logging.h"
#include "fastdds/rtps/security/logging/BuiltinLoggingType.h"
#include "fastrtps/utils/concurrent_queue.h"

#include <thread>
#include <atomic>

namespace eprosima {
namespace fastrtps {
namespace rtps {
namespace security {

/**
* @brief BuiltinLogging
*/
class BuiltinLogging final : public Logging
artivis marked this conversation as resolved.
Show resolved Hide resolved
{
using Message = std::pair<std::string,std::string>;
using MessagePtr = std::unique_ptr<Message>;

public:

BuiltinLogging();
~BuiltinLogging();

private:

/**
* @brief log_impl
* @param message
* @param category
* @param exception
*/
virtual void log_impl(const std::string& message,
const std::string& category,
SecurityException& exception) override;

BuiltinLoggingType convert(Message& msg);
void publish(BuiltinLoggingType& msg);

inline void stop() { stop_ = true; }
artivis marked this conversation as resolved.
Show resolved Hide resolved

//TODO(artivis):figure out which to use
// Publisher* publisher_; // publisher_ = DomainParticipant::create_publisher(...)
// DataWriter* data_writer_;

std::atomic_bool stop_;

std::thread thread_;

ConcurrentQueue<MessagePtr> queue_;
};

} //namespace security
} //namespace rtps
} //namespace fastrtps
} //namespace eprosima

#endif // _FASTDDS_RTPS_SECURITY_LOGGING_BUILTINLOGGING_H_
57 changes: 57 additions & 0 deletions include/fastdds/rtps/security/logging/BuiltinLoggingType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2020 Canonical ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
* @file BuiltinLoggingType.h
*/
#ifndef _FASTDDS_RTPS_SECURITY_LOGGING_BUILTINLOGGINGTYPE_H_
#define _FASTDDS_RTPS_SECURITY_LOGGING_BUILTINLOGGINGTYPE_H_

#include "fastdds/rtps/common/Types.h"
#include "fastdds/rtps/common/Time_t.h"
#include "fastdds/rtps/security/logging/LoggingLevel.h"
#include "fastdds/rtps/security/logging/NameValuePair.h"

#include <map>

namespace eprosima {
namespace fastrtps {
namespace rtps {
namespace security {

/**
* @brief The BuiltinLoggingType struct
*
* @note Definition in DDS-Sec v1.1 9.6
*/
struct BuiltinLoggingType final {
artivis marked this conversation as resolved.
Show resolved Hide resolved
octet facility; // Set to 0x0A (10). Indicates sec/auth msgs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fast RTPS seems to use four spaces for indentation. This only seems to be a single space, and elsewhere in the PR there are two. We should probably follow their established format. Try to make the code look like it was written by them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I will take care of 'fixing' all indentations...

LoggingLevel severity;
rtps::Time_t timestamp; // Since epoch 1970-01-01 00:00:00 +0000 (UTC)
std::string hostname; // IP host name of originator
std::string hostip; // IP address of originator
std::string appname; // Identify the device or application
std::string procid; // Process name/ID for syslog system
std::string msgid; // Identify the type of message
std::string message; // Free-form message
// Note that certain string keys (SD-IDs) are reserved by IANA
std::map<std::string, NameValuePairSeq> structured_data;
};

} //namespace security
} //namespace rtps
} //namespace fastrtps
} //namespace eprosima

#endif // _FASTDDS_RTPS_SECURITY_LOGGING_BUILTINLOGGINGTYPE_H_
97 changes: 97 additions & 0 deletions include/fastdds/rtps/security/logging/EventLogLevel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright 2020 Canonical ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
* @file EventLogLevel.h
*/
#ifndef _FASTDDS_RTPS_SECURITY_LOGGING_EVENTLOGLEVEL_H_
#define _FASTDDS_RTPS_SECURITY_LOGGING_EVENTLOGLEVEL_H_

#include "fastdds/rtps/security/exceptions/SecurityException.h"

namespace eprosima {
namespace fastrtps {
namespace rtps {
namespace security {

/**
* @brief The EventLogLevel enum
*
* @note Definition in DDS-Sec v1.1 8.6.2.1.1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section seems to outline the same information as 9.6, but with different names. I suspect we can remove this struct and use LoggingLevel instead, which seems to be what RTI has done. We should say something on the RTI forums or ping eProsima to make sure we're right, and to raise awareness of the error.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

*/
enum struct EventLogLevel : long
{
FATAL_LEVEL = 0, // security error causing a shutdown or failure of the Domain Participant
SEVERE_LEVEL, // major security error or fault
ERROR_LEVEL, // minor security error or fault
WARNING_LEVEL, // undesirable or unexpected behavior
NOTICE_LEVEL, // important security event
INFO_LEVEL, // interesting security event
DEBUG_LEVEL, // detailed information on the flow of the security events
TRACE_LEVEL // even more detailed information
};

inline bool string_to_EventLogLevel(const std::string& s,
EventLogLevel& l,
SecurityException& e)
{
//TODO(artivis): use an array of const char to avoid strings?
bool convert = true;
if (!bool(s.compare("0")) || !bool(s.compare("FATAL_LEVEL")))
{
l = EventLogLevel::FATAL_LEVEL;
}
else if (!s.compare("1") || !s.compare("SEVERE_LEVEL"))
{
l = EventLogLevel::SEVERE_LEVEL;
}
else if (!s.compare("2") || !s.compare("ERROR_LEVEL"))
{
l = EventLogLevel::ERROR_LEVEL;
}
else if (!s.compare("3") || !s.compare("WARNING_LEVEL"))
{
l = EventLogLevel::WARNING_LEVEL;
}
else if (!s.compare("4") || !s.compare("NOTICE_LEVEL"))
{
l = EventLogLevel::NOTICE_LEVEL;
}
else if (!s.compare("5") || !s.compare("INFO_LEVEL"))
{
l = EventLogLevel::INFO_LEVEL;
}
else if (!s.compare("6") || !s.compare("DEBUG_LEVEL"))
{
l = EventLogLevel::DEBUG_LEVEL;
}
else if (!s.compare("7") || !s.compare("TRACE_LEVEL"))
{
l = EventLogLevel::TRACE_LEVEL;
}
else
{
e = SecurityException("Unknown EventLogLevel");
convert = false;
}

return convert;
}

} //namespace security
} //namespace rtps
} //namespace fastrtps
} //namespace eprosima

#endif // _FASTDDS_RTPS_SECURITY_LOGGING_EVENTLOGLEVEL_H_
52 changes: 52 additions & 0 deletions include/fastdds/rtps/security/logging/LogOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2020 Canonical ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
* @file LogOptions.h
*/
#ifndef _FASTDDS_RTPS_SECURITY_LOGGING_LOGOPTIONS_H_
#define _FASTDDS_RTPS_SECURITY_LOGGING_LOGOPTIONS_H_

#include <string>

#include "fastdds/rtps/security/logging/EventLogLevel.h"

namespace eprosima {
namespace fastrtps {
namespace rtps {
namespace security {

/**
* @brief The LogOptions struct
* @note Definition in DDS-Sec v1.1 8.6.2.1
*/
struct LogOptions
{
//! Whether the log events should be distributed over DDS
bool distribute;

//! Level at which log messages will be logged.
//! Messages at or below the log_level are logged.
EventLogLevel event_log_level;

//! Full path to a local file
std::string log_file;
};

} //namespace security
} //namespace rtps
} //namespace fastrtps
} //namespace eprosima

#endif // _FASTDDS_RTPS_SECURITY_LOGGING_LOGOPTIONS_H_
Loading