blob: 7d85803db962855e4018a49e82e1176e21a77e63 [file] [log] [blame]
Alexander Afanasyev7e721412017-01-11 13:36:08 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2017 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#ifndef NDN_SECURITY_V2_VALIDATION_POLICY_HPP
23#define NDN_SECURITY_V2_VALIDATION_POLICY_HPP
24
25#include "validation-state.hpp"
26#include "certificate-request.hpp"
27#include "../../data.hpp"
28#include "../../interest.hpp"
29
30namespace ndn {
31namespace security {
32namespace v2 {
33
34/**
35 * @brief Abstraction that implements validation policy for Data and Interest packets
36 */
37class ValidationPolicy : noncopyable
38{
39public:
40 using ValidationContinuation = std::function<void(const shared_ptr<CertificateRequest>& certRequest,
41 const shared_ptr<ValidationState>& state)>;
42
43 virtual
44 ~ValidationPolicy() = default;
45
46 /**
47 * @brief Check @p data against the policy
48 *
49 * Depending on implementation of the policy, this check can be done synchronously or
50 * asynchronously.
51 *
52 * Semantics of checkPolicy has changed from v1::Validator
53 * - If packet violates policy, the policy should call `state->fail` with appropriate error
54 * code and error description.
55 * - If packet conforms to the policy and no further key retrievals are necessary,
56 * the policy should call continueValidation(state, nullptr)
57 * - If packet conforms to the policy and a key needs to be fetched, the policy should call
58 * continueValidation(state, <appropriate-key-request-instance>)
59 */
60 virtual void
61 checkPolicy(const Data& data, const shared_ptr<ValidationState>& state,
62 const ValidationContinuation& continueValidation) = 0;
63
64 /**
65 * @brief Check @p interest against the policy
66 *
67 * Depending on implementation of the policy, this check can be done synchronously or
68 * asynchronously.
69 *
70 * Semantics of checkPolicy has changed from v1::Validator
71 * - If packet violates policy, the policy should call `state->fail` with appropriate error
72 * code and error description.
73 * - If packet conforms to the policy and no further key retrievals are necessary,
74 * the policy should call continueValidation(state, nullptr)
75 * - If packet conforms to the policy and a key needs to be fetched, the policy should call
76 * continueValidation(state, <appropriate-key-request-instance>)
77 */
78 virtual void
79 checkPolicy(const Interest& interest, const shared_ptr<ValidationState>& state,
80 const ValidationContinuation& continueValidation) = 0;
81
82 /**
83 * @brief Check @p certificate against the policy
84 *
85 * Unless overridden by the policy, this check defaults to `checkPolicy(const Data&, ...)`.
86 *
87 * Depending on implementation of the policy, this check can be done synchronously or
88 * asynchronously.
89 *
90 * Semantics of checkPolicy has changed from v1::Validator
91 * - If packet violates policy, the policy should call `state->fail` with appropriate error
92 * code and error description.
93 * - If packet conforms to the policy and no further key retrievals are necessary,
94 * the policy should call continueValidation(state, nullptr)
95 * - If packet conforms to the policy and a key needs to be fetched, the policy should call
96 * continueValidation(state, <appropriate-key-request-instance>)
97 */
98 virtual void
99 checkPolicy(const Certificate& certificate, const shared_ptr<ValidationState>& state,
100 const ValidationContinuation& continueValidation)
101 {
102 checkPolicy(static_cast<const Data&>(certificate), state, continueValidation);
103 }
104};
105
106} // namespace v2
107} // namespace security
108} // namespace ndn
109
110#endif // NDN_SECURITY_V2_VALIDATION_POLICY_HPP