security: Include timestamp and nonce in signed interest and provide timestamp checking in ValidatorConf
Change-Id: I0adebd5c06b2d8d35ba13c5c03828b03334b7cec
Refs: #1642
diff --git a/src/security/conf/filter.hpp b/src/security/conf/filter.hpp
index fb2c15d..8d0601c 100644
--- a/src/security/conf/filter.hpp
+++ b/src/security/conf/filter.hpp
@@ -28,6 +28,7 @@
#include "../../data.hpp"
#include "../../interest.hpp"
#include "../../util/regex.hpp"
+#include "../security-common.hpp"
#include <boost/algorithm/string.hpp>
#include "common.hpp"
@@ -36,19 +37,42 @@
namespace security {
namespace conf {
+/**
+ * @brief Filter is one of the classes used by ValidatorConfig.
+ *
+ * The ValidatorConfig class consists of a set of rules.
+ * The Filter class is a part of a rule and is used to match packet.
+ * Matched packets will be checked against the checkers defined in the rule.
+ */
+
class Filter
{
public:
+
virtual
~Filter()
{
}
- virtual bool
- match(const Data& data) = 0;
+ bool
+ match(const Data& data)
+ {
+ return matchName(data.getName());
+ }
+ bool
+ match(const Interest& interest)
+ {
+ if (interest.getName().size() < signed_interest::MIN_LENGTH)
+ return false;
+
+ Name unsignedName = interest.getName().getPrefix(-signed_interest::MIN_LENGTH);
+ return matchName(unsignedName);
+ }
+
+protected:
virtual bool
- match(const Interest& interest) = 0;
+ matchName(const Name& name) = 0;
};
class RelationNameFilter : public Filter
@@ -72,25 +96,9 @@
{
}
+protected:
virtual bool
- match(const Data& data)
- {
- return match(data.getName());
- }
-
- virtual bool
- match(const Interest& interest)
- {
- if (interest.getName().size() < 2)
- return false;
-
- Name signedName = interest.getName().getPrefix(-2);
- return match(signedName);
- }
-
-private:
- bool
- match(const Name& name)
+ matchName(const Name& name)
{
switch (m_relation)
{
@@ -99,7 +107,7 @@
case RELATION_IS_PREFIX_OF:
return m_name.isPrefixOf(name);
case RELATION_IS_STRICT_PREFIX_OF:
- return (m_name.isPrefixOf(name) && m_name != name);
+ return (m_name.isPrefixOf(name) && m_name.size() < name.size());
default:
return false;
}
@@ -124,20 +132,11 @@
{
}
+protected:
virtual bool
- match(const Data& data)
+ matchName(const Name& name)
{
- return m_regex.match(data.getName());
- }
-
- virtual bool
- match(const Interest& interest)
- {
- if (interest.getName().size() < 2)
- return false;
-
- Name signedName = interest.getName().getPrefix(-2);
- return m_regex.match(signedName);
+ return m_regex.match(name);
}
private:
diff --git a/src/security/conf/key-locator-checker.hpp b/src/security/conf/key-locator-checker.hpp
index 21ff8b6..52cf888 100644
--- a/src/security/conf/key-locator-checker.hpp
+++ b/src/security/conf/key-locator-checker.hpp
@@ -27,6 +27,7 @@
#include "../../common.hpp"
#include "../../data.hpp"
#include "../../interest.hpp"
+#include "../security-common.hpp"
#include <boost/algorithm/string.hpp>
#include "common.hpp"
@@ -37,6 +38,15 @@
class KeyLocatorCheckerFactory;
+/**
+ * @brief KeyLocatorChecker is one of the classes used by ValidatorConfig.
+ *
+ * The ValidatorConfig class consists of a set of rules.
+ * The KeyLocatorChecker class is part of a rule and is used to check if the KeyLocator field of a
+ * packet satisfy the requirements.
+ */
+
+
class KeyLocatorChecker
{
public:
@@ -65,13 +75,13 @@
const KeyLocator& keyLocator,
std::string& failInfo)
{
- if (interest.getName().size() < 2)
+ if (interest.getName().size() < signed_interest::MIN_LENGTH)
{
failInfo = "No Signature";
return false;
}
- Name signedName = interest.getName().getPrefix(-2);
+ Name signedName = interest.getName().getPrefix(-signed_interest::MIN_LENGTH);
return check(signedName, keyLocator, failInfo);
}