Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | b48bbda | 2020-07-27 19:41:37 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017-2020, Regents of the University of California. |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndncert, a certificate management system based on NDN. |
| 6 | * |
| 7 | * ndncert is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndncert 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 General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ndncert authors and contributors. |
| 19 | */ |
| 20 | |
| 21 | #include "ca-memory.hpp" |
| 22 | |
Zhiyi Zhang | ef6b36a | 2020-09-22 21:20:59 -0700 | [diff] [blame] | 23 | #include <ndn-cxx/security/v2/validation-policy.hpp> |
Davide Pesavento | b48bbda | 2020-07-27 19:41:37 -0400 | [diff] [blame] | 24 | |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 25 | namespace ndn { |
| 26 | namespace ndncert { |
| 27 | |
| 28 | const std::string |
| 29 | CaMemory::STORAGE_TYPE = "ca-storage-memory"; |
| 30 | |
| 31 | NDNCERT_REGISTER_CA_STORAGE(CaMemory); |
| 32 | |
Zhiyi Zhang | d1d9f5a | 2020-10-05 18:04:23 -0700 | [diff] [blame^] | 33 | CaMemory::CaMemory(const Name& caName, const std::string& path) |
| 34 | : CaStorage() |
| 35 | { |
| 36 | } |
| 37 | |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 38 | CaState |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 39 | CaMemory::getRequest(const std::string& requestId) |
| 40 | { |
| 41 | auto search = m_requests.find(requestId); |
| 42 | if (search == m_requests.end()) { |
Zhiyi Zhang | d1d9f5a | 2020-10-05 18:04:23 -0700 | [diff] [blame^] | 43 | BOOST_THROW_EXCEPTION(std::runtime_error("Request " + requestId + " doest not exists")); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 44 | } |
| 45 | return search->second; |
| 46 | } |
| 47 | |
| 48 | void |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 49 | CaMemory::addRequest(const CaState& request) |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 50 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 51 | auto search = m_requests.find(request.m_requestId); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 52 | if (search == m_requests.end()) { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 53 | m_requests[request.m_requestId] = request; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 54 | } |
| 55 | else { |
Zhiyi Zhang | d1d9f5a | 2020-10-05 18:04:23 -0700 | [diff] [blame^] | 56 | BOOST_THROW_EXCEPTION(std::runtime_error("Request " + request.m_requestId + " already exists")); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
| 60 | void |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 61 | CaMemory::updateRequest(const CaState& request) |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 62 | { |
tylerliu | 09a00fd | 2020-10-04 11:11:18 -0700 | [diff] [blame] | 63 | m_requests[request.m_requestId].m_status = request.m_status; |
| 64 | m_requests[request.m_requestId].m_challengeState = request.m_challengeState; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void |
| 68 | CaMemory::deleteRequest(const std::string& requestId) |
| 69 | { |
| 70 | auto search = m_requests.find(requestId); |
tylerliu | 09a00fd | 2020-10-04 11:11:18 -0700 | [diff] [blame] | 71 | auto keyName = search->second.m_cert.getKeyName(); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 72 | if (search != m_requests.end()) { |
| 73 | m_requests.erase(search); |
| 74 | } |
| 75 | } |
| 76 | |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 77 | std::list<CaState> |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 78 | CaMemory::listAllRequests() |
| 79 | { |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 80 | std::list<CaState> result; |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 81 | for (const auto& entry : m_requests) { |
| 82 | result.push_back(entry.second); |
| 83 | } |
| 84 | return result; |
| 85 | } |
| 86 | |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 87 | std::list<CaState> |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 88 | CaMemory::listAllRequests(const Name& caName) |
| 89 | { |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 90 | std::list<CaState> result; |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 91 | for (const auto& entry : m_requests) { |
Suyong Won | 256c906 | 2020-05-11 02:45:56 -0700 | [diff] [blame] | 92 | if (entry.second.m_caPrefix == caName) { |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 93 | result.push_back(entry.second); |
| 94 | } |
| 95 | } |
| 96 | return result; |
| 97 | } |
| 98 | |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 99 | } // namespace ndncert |
| 100 | } // namespace ndn |