Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 1 | /** |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 2 | * Copyright (c) 2017-2019, 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 | |
| 20 | #ifndef NDNCERT_CHALLENGE_CREDENTIAL_HPP |
| 21 | #define NDNCERT_CHALLENGE_CREDENTIAL_HPP |
| 22 | |
| 23 | #include "../challenge-module.hpp" |
| 24 | |
| 25 | namespace ndn { |
| 26 | namespace ndncert { |
| 27 | |
| 28 | /** |
| 29 | * @brief Provide Credential based challenge |
| 30 | * |
| 31 | * Credential here means the certificate issued by a trust anchor. Once the requester |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 32 | * could proof his/her possession of an existing certificate from other certificate issuer, |
| 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. |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 42 | * 3. The content of the signed Data is the request id |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 43 | * |
Zhiyi Zhang | a9bda73 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 44 | * Failure info when application fails: |
| 45 | * FAILURE_INVALID_CREDENTIAL: When the cert issued from trust anchor or self-signed cert |
| 46 | * cannot be validated. |
| 47 | * FAILURE_INVALID_FORMAT: When the credential format is wrong. |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 48 | */ |
| 49 | class ChallengeCredential : public ChallengeModule |
| 50 | { |
| 51 | public: |
Zhiyi Zhang | 70fe258 | 2017-05-19 15:01:03 -0700 | [diff] [blame] | 52 | ChallengeCredential(const std::string& configPath = ""); |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 53 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 54 | // For CA |
| 55 | void |
| 56 | handleChallengeRequest(const JsonSection& params, CertificateRequest& request) override; |
| 57 | |
| 58 | // For Client |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 59 | JsonSection |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 60 | getRequirementForChallenge(int status, const std::string& challengeStatus) override; |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 61 | |
| 62 | JsonSection |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 63 | genChallengeRequestJson(int status, const std::string& challengeStatus, const JsonSection& params) override; |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 64 | |
| 65 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 66 | void |
| 67 | parseConfigFile(); |
| 68 | |
| 69 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 70 | static const std::string FAILURE_INVALID_CREDENTIAL; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 71 | static const std::string FAILURE_INVALID_FORMAT_CREDENTIAL; |
| 72 | static const std::string FAILURE_INVALID_FORMAT_SELF_SIGNED; |
Zhiyi Zhang | 70fe258 | 2017-05-19 15:01:03 -0700 | [diff] [blame] | 73 | static const std::string JSON_CREDENTIAL_CERT; |
| 74 | static const std::string JSON_CREDENTIAL_SELF; |
Zhiyi Zhang | 0a89b72 | 2017-04-28 17:56:01 -0700 | [diff] [blame] | 75 | |
| 76 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 77 | std::list<security::v2::Certificate> m_trustAnchors; |
| 78 | std::string m_configFile; |
| 79 | }; |
| 80 | |
| 81 | } // namespace ndncert |
| 82 | } // namespace ndn |
| 83 | |
| 84 | #endif // NDNCERT_CHALLENGE_CREDENTIAL_HPP |