Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 1 | /* |
Junxiao Shi | bdcf52e | 2022-04-24 21:49:01 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2022, Regents of the University of California. |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 3 | * |
| 4 | * This file is part of ndncert, a certificate management system based on NDN. |
| 5 | * |
| 6 | * ndncert is free software: you can redistribute it and/or modify it under the terms |
| 7 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 8 | * version 3 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 12 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received copies of the GNU General Public License along with |
| 15 | * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * See AUTHORS.md for complete list of ndncert authors and contributors. |
| 18 | */ |
| 19 | |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 20 | #ifndef NDNCERT_CHALLENGE_POSSESSION_HPP |
| 21 | #define NDNCERT_CHALLENGE_POSSESSION_HPP |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 22 | |
Zhiyi Zhang | dbd9d43 | 2020-10-07 15:56:27 -0700 | [diff] [blame] | 23 | #include "challenge-module.hpp" |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 24 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 25 | #include <ndn-cxx/security/key-chain.hpp> |
| 26 | |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 27 | namespace ndncert { |
| 28 | |
| 29 | /** |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 30 | * @brief Provide Possession based challenge |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 31 | * |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 32 | * Possession here means possession of the certificate issued by a trust anchor. Once the requester |
| 33 | * could proof his/her possession of an existing certificate from this or other certificate issuer, |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 34 | * the requester could finish the challenge. |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 35 | * |
Zhiyi Zhang | 70fe258 | 2017-05-19 15:01:03 -0700 | [diff] [blame] | 36 | * The requester needs to provide the proof of the possession of a certificate issued by |
| 37 | * a trust anchor. The challenge require the requester to pass the BASE64 certificate and |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 38 | * a BASE64 Data packet signed by the credential pub key and whose content is the request id. |
Zhiyi Zhang | 70fe258 | 2017-05-19 15:01:03 -0700 | [diff] [blame] | 39 | * |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 40 | * The main process of this challenge module is: |
| 41 | * 1. Requester provides a certificate signed by that trusted certificate as credential. |
| 42 | * 2. The challenge module will verify the signature of the credential. |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 43 | * 3. The challenge module will Provide a 16 octet random number data. |
| 44 | * 3. The Requester signs the signed Data to prove it possess the private key |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 45 | * |
Zhiyi Zhang | a9bda73 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 46 | * Failure info when application fails: |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 47 | * INVALID_PARAMETER: When the cert issued from trust anchor or self-signed cert |
Zhiyi Zhang | a9bda73 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 48 | * cannot be validated. |
| 49 | * FAILURE_INVALID_FORMAT: When the credential format is wrong. |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 50 | */ |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 51 | class ChallengePossession : public ChallengeModule |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 52 | { |
| 53 | public: |
Junxiao Shi | bdcf52e | 2022-04-24 21:49:01 +0000 | [diff] [blame] | 54 | explicit |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 55 | ChallengePossession(const std::string& configPath = ""); |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 56 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 57 | // For CA |
Zhiyi Zhang | aafc55e | 2020-09-28 17:54:48 -0700 | [diff] [blame] | 58 | std::tuple<ErrorCode, std::string> |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 59 | handleChallengeRequest(const Block& params, ca::RequestState& request) override; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 60 | |
| 61 | // For Client |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 62 | std::multimap<std::string, std::string> |
Zhiyi Zhang | 4604983 | 2020-09-28 17:08:12 -0700 | [diff] [blame] | 63 | getRequestedParameterList(Status status, const std::string& challengeStatus) override; |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 64 | |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 65 | Block |
Zhiyi Zhang | 4604983 | 2020-09-28 17:08:12 -0700 | [diff] [blame] | 66 | genChallengeRequestTLV(Status status, const std::string& challengeStatus, |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 67 | const std::multimap<std::string, std::string>& params) override; |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 68 | |
Zhiyi Zhang | ead9f00 | 2020-10-03 15:42:52 -0700 | [diff] [blame] | 69 | static void |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 70 | fulfillParameters(std::multimap<std::string, std::string>& params, |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 71 | ndn::KeyChain& keyChain, const Name& issuedCertName, |
Junxiao Shi | bdcf52e | 2022-04-24 21:49:01 +0000 | [diff] [blame] | 72 | ndn::span<const uint8_t, 16> nonce); |
Zhiyi Zhang | ead9f00 | 2020-10-03 15:42:52 -0700 | [diff] [blame] | 73 | |
| 74 | // challenge parameters |
| 75 | static const std::string PARAMETER_KEY_CREDENTIAL_CERT; |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 76 | static const std::string PARAMETER_KEY_NONCE; |
| 77 | static const std::string PARAMETER_KEY_PROOF; |
| 78 | static const std::string NEED_PROOF; |
Zhiyi Zhang | ead9f00 | 2020-10-03 15:42:52 -0700 | [diff] [blame] | 79 | |
tylerliu | dd35991 | 2020-10-20 13:05:22 -0700 | [diff] [blame] | 80 | NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 81 | void |
| 82 | parseConfigFile(); |
| 83 | |
tylerliu | dd35991 | 2020-10-20 13:05:22 -0700 | [diff] [blame] | 84 | NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 85 | std::list<Certificate> m_trustAnchors; |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 86 | std::string m_configFile; |
| 87 | }; |
| 88 | |
| 89 | } // namespace ndncert |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 90 | |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 91 | #endif // NDNCERT_CHALLENGE_POSSESSION_HPP |