Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
tylerliu | 182bc53 | 2020-09-25 01:54:45 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2020, Regents of the University of California. |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -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 | |
Zhiyi Zhang | 34f03f0 | 2020-10-29 18:34:42 -0700 | [diff] [blame] | 21 | #include "detail/ca-request-state.hpp" |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 22 | #include <ndn-cxx/util/indented-stream.hpp> |
| 23 | |
| 24 | namespace ndn { |
| 25 | namespace ndncert { |
| 26 | |
Zhiyi Zhang | 14f0bc8 | 2020-10-12 13:02:23 -0700 | [diff] [blame] | 27 | std::string statusToString(Status status) { |
| 28 | switch (status) |
| 29 | { |
| 30 | case Status::BEFORE_CHALLENGE: |
| 31 | return "Before challenge"; |
| 32 | case Status::CHALLENGE: |
| 33 | return "In challenge"; |
| 34 | case Status::PENDING: |
| 35 | return "Pending after challenge"; |
| 36 | case Status::SUCCESS: |
| 37 | return "Success"; |
| 38 | case Status::FAILURE: |
| 39 | return "Failure"; |
| 40 | case Status::NOT_STARTED: |
| 41 | return "Not started"; |
| 42 | case Status::ENDED: |
| 43 | return "Ended"; |
| 44 | default: |
| 45 | return "Unrecognized status"; |
| 46 | } |
| 47 | } |
| 48 | |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 49 | namespace ca { |
| 50 | |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 51 | ChallengeState::ChallengeState(const std::string& challengeStatus, |
Zhiyi Zhang | 3243728 | 2020-10-10 16:15:37 -0700 | [diff] [blame] | 52 | const time::system_clock::TimePoint& challengeTp, |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 53 | size_t remainingTries, time::seconds remainingTime, |
| 54 | JsonSection&& challengeSecrets) |
| 55 | : m_challengeStatus(challengeStatus) |
| 56 | , m_timestamp(challengeTp) |
| 57 | , m_remainingTries(remainingTries) |
| 58 | , m_remainingTime(remainingTime) |
| 59 | , m_secrets(std::move(challengeSecrets)) |
| 60 | { |
| 61 | } |
| 62 | |
Zhiyi Zhang | c9ada1b | 2020-10-29 19:13:15 -0700 | [diff] [blame^] | 63 | RequestState::RequestState(const Name& caName, const RequestId& requestId, RequestType requestType, Status status, |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 64 | const security::Certificate& cert, Block encryptionKey, uint32_t aesBlockCounter) |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 65 | : m_caPrefix(caName) |
| 66 | , m_requestId(requestId) |
| 67 | , m_requestType(requestType) |
| 68 | , m_status(status) |
| 69 | , m_cert(cert) |
tylerliu | 8e170d6 | 2020-09-30 01:31:53 -0700 | [diff] [blame] | 70 | , m_encryptionKey(std::move(encryptionKey)) |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 71 | , m_aesBlockCounter(aesBlockCounter) |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 72 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Zhiyi Zhang | c9ada1b | 2020-10-29 19:13:15 -0700 | [diff] [blame^] | 75 | RequestState::RequestState(const Name& caName, const RequestId& requestId, RequestType requestType, Status status, |
tylerliu | a7bea66 | 2020-10-08 18:51:02 -0700 | [diff] [blame] | 76 | const security::Certificate& cert, const std::string& challengeType, |
Zhiyi Zhang | 3243728 | 2020-10-10 16:15:37 -0700 | [diff] [blame] | 77 | const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp, |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 78 | size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets, |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 79 | Block encryptionKey, uint32_t aesBlockCounter) |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 80 | : m_caPrefix(caName) |
| 81 | , m_requestId(requestId) |
| 82 | , m_requestType(requestType) |
| 83 | , m_status(status) |
| 84 | , m_cert(cert) |
Zhiyi Zhang | 156bf35 | 2020-09-30 17:45:43 -0700 | [diff] [blame] | 85 | , m_encryptionKey(std::move(encryptionKey)) |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 86 | , m_aesBlockCounter(aesBlockCounter) |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 87 | , m_challengeType(challengeType) |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 88 | , m_challengeState(ChallengeState(challengeStatus, challengeTp, remainingTries, remainingTime, std::move(challengeSecrets))) |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 89 | { |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | std::ostream& |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 93 | operator<<(std::ostream& os, const RequestState& request) |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 94 | { |
Zhiyi Zhang | d93c0bb | 2020-10-05 22:06:05 -0700 | [diff] [blame] | 95 | os << "Request's CA name: " << request.m_caPrefix << "\n"; |
Zhiyi Zhang | 8fdb36b | 2020-10-18 11:58:51 -0700 | [diff] [blame] | 96 | os << "Request's request ID: " << toHex(request.m_requestId.data(), request.m_requestId.size()) << "\n"; |
Zhiyi Zhang | d93c0bb | 2020-10-05 22:06:05 -0700 | [diff] [blame] | 97 | os << "Request's status: " << statusToString(request.m_status) << "\n"; |
| 98 | os << "Request's challenge type: " << request.m_challengeType << "\n"; |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 99 | if (request.m_challengeState) { |
Zhiyi Zhang | d93c0bb | 2020-10-05 22:06:05 -0700 | [diff] [blame] | 100 | os << "Challenge Status: " << request.m_challengeState->m_challengeStatus << "\n"; |
| 101 | os << "Challenge remaining tries:" << request.m_challengeState->m_remainingTries << " times\n"; |
| 102 | os << "Challenge remaining time: " << request.m_challengeState->m_remainingTime.count() << " seconds\n"; |
| 103 | os << "Challenge last update: " << time::toIsoString(request.m_challengeState->m_timestamp) << "\n"; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 104 | } |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 105 | os << "Certificate:\n"; |
| 106 | util::IndentedStream os2(os, " "); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 107 | os2 << request.m_cert; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 108 | return os; |
| 109 | } |
| 110 | |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 111 | } // namespace ca |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 112 | } // namespace ndncert |
| 113 | } // namespace ndn |