Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 1 | /* -*- 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 | #include "validation-policy-simple-hierarchy.hpp" |
| 23 | |
| 24 | namespace ndn { |
| 25 | namespace security { |
| 26 | namespace v2 { |
| 27 | |
| 28 | void |
| 29 | ValidationPolicySimpleHierarchy::checkPolicy(const Data& data, const shared_ptr<ValidationState>& state, |
| 30 | const ValidationContinuation& continueValidation) |
| 31 | { |
Junxiao Shi | 830ba97 | 2017-06-23 22:44:41 +0000 | [diff] [blame] | 32 | Name klName = getKeyLocatorName(data, *state); |
| 33 | if (!state->getOutcome()) { // already failed |
| 34 | return; |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 35 | } |
Junxiao Shi | 830ba97 | 2017-06-23 22:44:41 +0000 | [diff] [blame] | 36 | |
| 37 | if (klName.getPrefix(-2).isPrefixOf(data.getName())) { |
| 38 | continueValidation(make_shared<CertificateRequest>(Interest(klName)), state); |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 39 | } |
| 40 | else { |
| 41 | state->fail({ValidationError::Code::INVALID_KEY_LOCATOR, "Data signing policy violation for " + |
Junxiao Shi | 830ba97 | 2017-06-23 22:44:41 +0000 | [diff] [blame] | 42 | data.getName().toUri() + " by " + klName.toUri()}); |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | void |
| 47 | ValidationPolicySimpleHierarchy::checkPolicy(const Interest& interest, const shared_ptr<ValidationState>& state, |
| 48 | const ValidationContinuation& continueValidation) |
| 49 | { |
Junxiao Shi | 830ba97 | 2017-06-23 22:44:41 +0000 | [diff] [blame] | 50 | Name klName = getKeyLocatorName(interest, *state); |
| 51 | if (!state->getOutcome()) { // already failed |
| 52 | return; |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 53 | } |
Junxiao Shi | 830ba97 | 2017-06-23 22:44:41 +0000 | [diff] [blame] | 54 | |
| 55 | if (klName.getPrefix(-2).isPrefixOf(interest.getName())) { |
| 56 | continueValidation(make_shared<CertificateRequest>(Interest(klName)), state); |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 57 | } |
| 58 | else { |
| 59 | state->fail({ValidationError::Code::INVALID_KEY_LOCATOR, "Interest signing policy violation for " + |
Junxiao Shi | 830ba97 | 2017-06-23 22:44:41 +0000 | [diff] [blame] | 60 | interest.getName().toUri() + " by " + klName.toUri()}); |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | } // namespace v2 |
| 65 | } // namespace security |
| 66 | } // namespace ndn |