38 #include <boost/filesystem.hpp> 54 static optional<std::string>
58 if (signerTag ==
nullptr) {
62 return signerTag->get().toUri();
73 const ValidationContinuation& continueValidation)
final 76 if (!state->getOutcome()) {
83 auto state1 = dynamic_pointer_cast<security::InterestValidationState>(state);
84 state1->getOriginalInterest().setTag(make_shared<SignerTag>(klName));
86 continueValidation(make_shared<security::CertificateRequest>(klName), state);
91 const ValidationContinuation&)
final 95 BOOST_ASSERT_MSG(
false,
"Data should not be passed to this policy");
99 shared_ptr<CommandAuthenticator>
105 CommandAuthenticator::CommandAuthenticator() =
default;
111 processConfig(std::forward<decltype(args)>(args)...);
116 CommandAuthenticator::processConfig(
const ConfigSection& section,
bool isDryRun,
const std::string& filename)
120 for (
auto& kv : m_validators) {
121 kv.second = make_shared<security::Validator>(
122 make_unique<security::ValidationPolicyCommandInterest>(make_unique<CommandAuthenticatorValidationPolicy>()),
123 make_unique<security::CertificateFetcherOffline>());
127 if (section.empty()) {
131 int authSectionIndex = 0;
132 for (
const auto& kv : section) {
133 if (kv.first !=
"authorize") {
138 std::string certfile;
140 certfile = authSection.get<std::string>(
"certfile");
142 catch (
const boost::property_tree::ptree_error&) {
148 shared_ptr<security::Certificate> cert;
149 if (certfile ==
"any") {
151 NFD_LOG_WARN(
"'certfile any' is intended for demo purposes only and " 152 "SHOULD NOT be used in production environments");
155 using namespace boost::filesystem;
156 path certfilePath = absolute(certfile, path(filename).parent_path());
157 cert = ndn::io::load<security::Certificate>(certfilePath.string());
158 if (cert ==
nullptr) {
160 " for authorize[" +
to_string(authSectionIndex) +
"]"));
166 privSection = &authSection.get_child(
"privileges");
168 catch (
const boost::property_tree::ptree_error&) {
173 if (privSection->empty()) {
174 NFD_LOG_WARN(
"No privileges granted to certificate " << certfile);
176 for (
const auto& kv : *privSection) {
177 const std::string& module = kv.first;
178 auto found = m_validators.find(module);
179 if (
found == m_validators.end()) {
181 "' under authorize[" +
to_string(authSectionIndex) +
"]"));
189 found->second = make_shared<security::Validator>(make_unique<security::ValidationPolicyAcceptAll>(),
190 make_unique<security::CertificateFetcherOffline>());
191 NFD_LOG_INFO(
"authorize module=" << module <<
" signer=any");
194 const Name& keyName = cert->getKeyName();
195 security::Certificate certCopy = *cert;
197 NFD_LOG_INFO(
"authorize module=" << module <<
" signer=" << keyName <<
" certfile=" << certfile);
208 m_validators[module];
210 auto self = this->shared_from_this();
215 auto validator =
self->m_validators.at(module);
217 auto successCb = [
accept, validator] (
const Interest& interest1) {
219 BOOST_ASSERT(signer1 ||
220 dynamic_cast<security::ValidationPolicyAcceptAll*>(&validator->getPolicy()) !=
nullptr);
221 std::string signer = signer1.value_or(
"*");
222 NFD_LOG_DEBUG(
"accept " << interest1.getName() <<
" signer=" << signer);
226 auto failureCb = [reject] (
const Interest& interest1,
const security::ValidationError& err) {
229 switch (err.getCode()) {
230 case security::ValidationError::NO_SIGNATURE:
231 case security::ValidationError::INVALID_KEY_LOCATOR:
232 reply = RejectReply::SILENT;
234 case security::ValidationError::POLICY_ERROR:
236 reply = RejectReply::SILENT;
246 validator->validate(interest, successCb, failureCb);
249 NFD_LOG_DEBUG(
"reject " << interest.getName() <<
" signer=" <<
shared_ptr< T > getTag() const
get a tag item
#define NFD_LOG_INIT(name)
std::string to_string(const T &val)
Accept any value the remote endpoint offers.
RejectReply
indicate how to reply in case authorization is rejected
reply with a ControlResponse where StatusCode is 403
configuration file parsing utility
a validation policy that only permits Interest signed by a trust anchor
Represents an Interest packet.
std::function< void(const std::string &requester)> AcceptContinuation
a function to be called if authorization is successful
void setConfigFile(ConfigFile &configFile)
Catch-all error for security policy errors that don't fit in other categories.
provides a tag type for simple types
static Name getKeyLocatorName(const SignatureInfo &si, ValidationState &state)
std::function< void(RejectReply reply)> RejectContinuation
a function to be called if authorization is rejected
Copyright (c) 2011-2015 Regents of the University of California.
void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
ndn::mgmt::Authorization makeAuthorization(const std::string &module, const std::string &verb)
static optional< std::string > getSignerFromTag(const Interest &interest)
obtain signer from SignerTag attached to Interest, if available
const size_t MIN_SIZE
minimal number of components for Command Interest
boost::property_tree::ptree ConfigSection
a config file section
Represents an absolute name.
void checkPolicy(const Interest &interest, const shared_ptr< security::ValidationState > &state, const ValidationContinuation &continueValidation) final
base class for a struct that contains ControlCommand parameters
size_t size() const
Returns the number of components.
Provides ControlCommand authorization according to NFD configuration file.
static shared_ptr< CommandAuthenticator > create()
const Name & getName() const noexcept
void checkPolicy(const Data &, const shared_ptr< security::ValidationState > &, const ValidationContinuation &) final
Represents a Data packet.
std::function< void(const Name &prefix, const Interest &interest, const ControlParameters *params, const AcceptContinuation &accept, const RejectContinuation &reject)> Authorization
a function that performs authorization
const nullopt_t nullopt((nullopt_t::init()))