Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2017-2020, Regents of the University of California. |
| 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 | |
tylerliu | bb63036 | 2020-11-10 11:31:35 -0800 | [diff] [blame] | 21 | #ifndef NDNCERT_REQUESTER_REQUEST_STATE_HPP |
| 22 | #define NDNCERT_REQUESTER_REQUEST_STATE_HPP |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 23 | |
Zhiyi Zhang | 34f03f0 | 2020-10-29 18:34:42 -0700 | [diff] [blame] | 24 | #include "detail/ca-request-state.hpp" |
Zhiyi Zhang | dc25ddf | 2020-10-20 14:28:55 -0700 | [diff] [blame] | 25 | #include "detail/crypto-helpers.hpp" |
Zhiyi Zhang | 3f20f95 | 2020-11-19 19:26:43 -0800 | [diff] [blame] | 26 | #include "detail/profile-storage.hpp" |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
| 29 | namespace ndncert { |
Zhiyi Zhang | 3002e6b | 2020-10-29 18:54:07 -0700 | [diff] [blame] | 30 | namespace requester { |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 31 | |
tylerliu | bb63036 | 2020-11-10 11:31:35 -0800 | [diff] [blame] | 32 | struct RequestState { |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 33 | explicit |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 34 | RequestState(security::KeyChain& keyChain, const CaProfile& profile, RequestType requestType); |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 37 | * @brief The CA profile for this request. |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 38 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 39 | CaProfile caProfile; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 40 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 41 | * @brief The local keychain to generate and install identities, keys and certificates |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 42 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 43 | security::KeyChain& keyChain; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 44 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 45 | * @brief The type of request. Either NEW, RENEW, or REVOKE. |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 46 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 47 | RequestType type; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 48 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 49 | * @brief The identity name for the requesting certificate. |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 50 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 51 | Name identityName; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 52 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 53 | * @brief The keypair for the request. |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 54 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 55 | security::Key keyPair; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 56 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 57 | * @brief The CA-generated request ID for the request. |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 58 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 59 | RequestId requestId; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 60 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 61 | * @brief The current status of the request. |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 62 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 63 | Status status = Status::BEFORE_CHALLENGE; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 64 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 65 | * @brief The type of challenge chosen. |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 66 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 67 | std::string challengeType; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 68 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 69 | * @brief The status of the current challenge. |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 70 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 71 | std::string challengeStatus; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 72 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 73 | * @brief The remaining number of tries left for the challenge |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 74 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 75 | int remainingTries = 0; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 76 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 77 | * @brief The time this challenge will remain fresh |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 78 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 79 | time::system_clock::TimePoint freshBefore; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 80 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 81 | * @brief the name of the certificate being issued. |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 82 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 83 | Name issuedCertName; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 84 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 85 | * @brief ecdh state. |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 86 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 87 | ECDHState ecdh; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 88 | /** |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 89 | * @brief AES key derived from the ecdh shared secret. |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 90 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 91 | std::array<uint8_t, 16> aesKey = {}; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 92 | /** |
Zhiyi Zhang | 4f1c010 | 2020-12-21 15:08:09 -0800 | [diff] [blame] | 93 | * @brief The last Initialization Vector used by the AES encryption. |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 94 | */ |
Zhiyi Zhang | 4f1c010 | 2020-12-21 15:08:09 -0800 | [diff] [blame] | 95 | std::vector<uint8_t> encryptionIv; |
| 96 | /** |
| 97 | * @brief The last Initialization Vector used by the other side's AES encryption. |
| 98 | */ |
| 99 | std::vector<uint8_t> decryptionIv; |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 100 | /** |
| 101 | * @brief State about how identity/key is generated. |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 102 | */ |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 103 | bool isNewlyCreatedIdentity = false; |
| 104 | bool isNewlyCreatedKey = false; |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 105 | /** |
| 106 | * @brief Store Nonce for signature |
| 107 | */ |
| 108 | std::array<uint8_t, 16> nonce = {}; |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
Zhiyi Zhang | 3002e6b | 2020-10-29 18:54:07 -0700 | [diff] [blame] | 111 | } // namespace requester |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 112 | } // namespace ndncert |
| 113 | } // namespace ndn |
Zhiyi Zhang | f2306f7 | 2020-10-09 11:26:05 -0700 | [diff] [blame] | 114 | |
tylerliu | bb63036 | 2020-11-10 11:31:35 -0800 | [diff] [blame] | 115 | #endif // NDNCERT_REQUESTER_REQUEST_STATE_HPP |