Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 1 | /** |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, 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 | |
| 25 | namespace ndn { |
| 26 | namespace ndncert { |
| 27 | |
| 28 | /** |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 29 | * @brief Provide Possession based challenge |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 30 | * |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 31 | * Possession here means possession of the certificate issued by a trust anchor. Once the requester |
| 32 | * 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] | 33 | * the requester could finish the challenge. |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 34 | * |
Zhiyi Zhang | 70fe258 | 2017-05-19 15:01:03 -0700 | [diff] [blame] | 35 | * The requester needs to provide the proof of the possession of a certificate issued by |
| 36 | * 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] | 37 | * 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] | 38 | * |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 39 | * The main process of this challenge module is: |
| 40 | * 1. Requester provides a certificate signed by that trusted certificate as credential. |
| 41 | * 2. The challenge module will verify the signature of the credential. |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 42 | * 3. The challenge module will Provide a 16 octet random number data. |
| 43 | * 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] | 44 | * |
Zhiyi Zhang | a9bda73 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 45 | * Failure info when application fails: |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 46 | * 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] | 47 | * cannot be validated. |
| 48 | * FAILURE_INVALID_FORMAT: When the credential format is wrong. |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 49 | */ |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 50 | class ChallengePossession : public ChallengeModule |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 51 | { |
| 52 | public: |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 53 | ChallengePossession(const std::string& configPath = ""); |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 54 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 55 | // For CA |
Zhiyi Zhang | aafc55e | 2020-09-28 17:54:48 -0700 | [diff] [blame] | 56 | std::tuple<ErrorCode, std::string> |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 57 | handleChallengeRequest(const Block& params, ca::RequestState& request) override; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 58 | |
| 59 | // For Client |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 60 | std::multimap<std::string, std::string> |
Zhiyi Zhang | 4604983 | 2020-09-28 17:08:12 -0700 | [diff] [blame] | 61 | getRequestedParameterList(Status status, const std::string& challengeStatus) override; |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 62 | |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 63 | Block |
Zhiyi Zhang | 4604983 | 2020-09-28 17:08:12 -0700 | [diff] [blame] | 64 | genChallengeRequestTLV(Status status, const std::string& challengeStatus, |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 65 | const std::multimap<std::string, std::string>& params) override; |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 66 | |
Zhiyi Zhang | ead9f00 | 2020-10-03 15:42:52 -0700 | [diff] [blame] | 67 | static void |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 68 | fulfillParameters(std::multimap<std::string, std::string>& params, |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 69 | KeyChain& keyChain, const Name& issuedCertName, const std::array<uint8_t, 16>& nonce); |
Zhiyi Zhang | ead9f00 | 2020-10-03 15:42:52 -0700 | [diff] [blame] | 70 | |
| 71 | // challenge parameters |
| 72 | static const std::string PARAMETER_KEY_CREDENTIAL_CERT; |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 73 | static const std::string PARAMETER_KEY_NONCE; |
| 74 | static const std::string PARAMETER_KEY_PROOF; |
| 75 | static const std::string NEED_PROOF; |
Zhiyi Zhang | ead9f00 | 2020-10-03 15:42:52 -0700 | [diff] [blame] | 76 | |
tylerliu | dd35991 | 2020-10-20 13:05:22 -0700 | [diff] [blame] | 77 | NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 78 | void |
| 79 | parseConfigFile(); |
| 80 | |
tylerliu | dd35991 | 2020-10-20 13:05:22 -0700 | [diff] [blame] | 81 | NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
tylerliu | a7bea66 | 2020-10-08 18:51:02 -0700 | [diff] [blame] | 82 | std::list<security::Certificate> m_trustAnchors; |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 83 | std::string m_configFile; |
| 84 | }; |
| 85 | |
| 86 | } // namespace ndncert |
| 87 | } // namespace ndn |
| 88 | |
tylerliu | f51e316 | 2020-12-20 19:22:59 -0800 | [diff] [blame] | 89 | #endif // NDNCERT_CHALLENGE_POSSESSION_HPP |