blob: 165e20ee5e8b0fa2488c9f3c7cfe6951fc914fa2 [file] [log] [blame]
Zhiyi Zhang0a89b722017-04-28 17:56:01 -07001/**
Zhiyi Zhang74c61142020-10-07 21:00:49 -07002 * Copyright (c) 2017-2020, Regents of the University of California.
Zhiyi Zhang0a89b722017-04-28 17:56:01 -07003 *
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
tylerliuf51e3162020-12-20 19:22:59 -080020#ifndef NDNCERT_CHALLENGE_POSSESSION_HPP
21#define NDNCERT_CHALLENGE_POSSESSION_HPP
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070022
Zhiyi Zhangdbd9d432020-10-07 15:56:27 -070023#include "challenge-module.hpp"
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070024
25namespace ndn {
26namespace ndncert {
27
28/**
tylerliuf51e3162020-12-20 19:22:59 -080029 * @brief Provide Possession based challenge
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070030 *
tylerliuf51e3162020-12-20 19:22:59 -080031 * 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 Zhangaf7c2902019-03-14 22:13:21 -070033 * the requester could finish the challenge.
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070034 *
Zhiyi Zhang70fe2582017-05-19 15:01:03 -070035 * 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 Zhangaf7c2902019-03-14 22:13:21 -070037 * a BASE64 Data packet signed by the credential pub key and whose content is the request id.
Zhiyi Zhang70fe2582017-05-19 15:01:03 -070038 *
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070039 * 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.
tylerliuf51e3162020-12-20 19:22:59 -080042 * 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 Zhang0a89b722017-04-28 17:56:01 -070044 *
Zhiyi Zhanga9bda732017-05-20 22:58:55 -070045 * Failure info when application fails:
tylerliuf51e3162020-12-20 19:22:59 -080046 * INVALID_PARAMETER: When the cert issued from trust anchor or self-signed cert
Zhiyi Zhanga9bda732017-05-20 22:58:55 -070047 * cannot be validated.
48 * FAILURE_INVALID_FORMAT: When the credential format is wrong.
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070049 */
tylerliuf51e3162020-12-20 19:22:59 -080050class ChallengePossession : public ChallengeModule
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070051{
52public:
tylerliuf51e3162020-12-20 19:22:59 -080053 ChallengePossession(const std::string& configPath = "");
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070054
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070055 // For CA
Zhiyi Zhangaafc55e2020-09-28 17:54:48 -070056 std::tuple<ErrorCode, std::string>
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070057 handleChallengeRequest(const Block& params, ca::RequestState& request) override;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070058
59 // For Client
tylerliu40226332020-11-11 15:37:16 -080060 std::multimap<std::string, std::string>
Zhiyi Zhang46049832020-09-28 17:08:12 -070061 getRequestedParameterList(Status status, const std::string& challengeStatus) override;
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070062
Suyong Won19fba4d2020-05-09 13:39:46 -070063 Block
Zhiyi Zhang46049832020-09-28 17:08:12 -070064 genChallengeRequestTLV(Status status, const std::string& challengeStatus,
tylerliuf2e6bb52020-12-13 13:23:05 -080065 const std::multimap<std::string, std::string>& params) override;
Suyong Won19fba4d2020-05-09 13:39:46 -070066
Zhiyi Zhangead9f002020-10-03 15:42:52 -070067 static void
tylerliu40226332020-11-11 15:37:16 -080068 fulfillParameters(std::multimap<std::string, std::string>& params,
tylerliuf51e3162020-12-20 19:22:59 -080069 KeyChain& keyChain, const Name& issuedCertName, const std::array<uint8_t, 16>& nonce);
Zhiyi Zhangead9f002020-10-03 15:42:52 -070070
71 // challenge parameters
72 static const std::string PARAMETER_KEY_CREDENTIAL_CERT;
tylerliuf51e3162020-12-20 19:22:59 -080073 static const std::string PARAMETER_KEY_NONCE;
74 static const std::string PARAMETER_KEY_PROOF;
75 static const std::string NEED_PROOF;
Zhiyi Zhangead9f002020-10-03 15:42:52 -070076
tylerliudd359912020-10-20 13:05:22 -070077NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070078 void
79 parseConfigFile();
80
tylerliudd359912020-10-20 13:05:22 -070081NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
tylerliua7bea662020-10-08 18:51:02 -070082 std::list<security::Certificate> m_trustAnchors;
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070083 std::string m_configFile;
84};
85
86} // namespace ndncert
87} // namespace ndn
88
tylerliuf51e3162020-12-20 19:22:59 -080089#endif // NDNCERT_CHALLENGE_POSSESSION_HPP