blob: ab5e641497297608e8c6bcfb63f7ec795d027660 [file] [log] [blame]
Davide Pesavento0dc02012021-11-23 22:55:03 -05001/*
2 * Copyright (c) 2017-2021, 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
Davide Pesavento0dc02012021-11-23 22:55:03 -050025#include <ndn-cxx/security/key-chain.hpp>
26
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070027namespace ndncert {
28
29/**
tylerliuf51e3162020-12-20 19:22:59 -080030 * @brief Provide Possession based challenge
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070031 *
tylerliuf51e3162020-12-20 19:22:59 -080032 * 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 Zhangaf7c2902019-03-14 22:13:21 -070034 * the requester could finish the challenge.
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070035 *
Zhiyi Zhang70fe2582017-05-19 15:01:03 -070036 * 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 Zhangaf7c2902019-03-14 22:13:21 -070038 * a BASE64 Data packet signed by the credential pub key and whose content is the request id.
Zhiyi Zhang70fe2582017-05-19 15:01:03 -070039 *
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070040 * 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.
tylerliuf51e3162020-12-20 19:22:59 -080043 * 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 Zhang0a89b722017-04-28 17:56:01 -070045 *
Zhiyi Zhanga9bda732017-05-20 22:58:55 -070046 * Failure info when application fails:
tylerliuf51e3162020-12-20 19:22:59 -080047 * INVALID_PARAMETER: When the cert issued from trust anchor or self-signed cert
Zhiyi Zhanga9bda732017-05-20 22:58:55 -070048 * cannot be validated.
49 * FAILURE_INVALID_FORMAT: When the credential format is wrong.
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070050 */
tylerliuf51e3162020-12-20 19:22:59 -080051class ChallengePossession : public ChallengeModule
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070052{
53public:
tylerliuf51e3162020-12-20 19:22:59 -080054 ChallengePossession(const std::string& configPath = "");
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070055
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070056 // For CA
Zhiyi Zhangaafc55e2020-09-28 17:54:48 -070057 std::tuple<ErrorCode, std::string>
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070058 handleChallengeRequest(const Block& params, ca::RequestState& request) override;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070059
60 // For Client
tylerliu40226332020-11-11 15:37:16 -080061 std::multimap<std::string, std::string>
Zhiyi Zhang46049832020-09-28 17:08:12 -070062 getRequestedParameterList(Status status, const std::string& challengeStatus) override;
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070063
Suyong Won19fba4d2020-05-09 13:39:46 -070064 Block
Zhiyi Zhang46049832020-09-28 17:08:12 -070065 genChallengeRequestTLV(Status status, const std::string& challengeStatus,
tylerliuf2e6bb52020-12-13 13:23:05 -080066 const std::multimap<std::string, std::string>& params) override;
Suyong Won19fba4d2020-05-09 13:39:46 -070067
Zhiyi Zhangead9f002020-10-03 15:42:52 -070068 static void
tylerliu40226332020-11-11 15:37:16 -080069 fulfillParameters(std::multimap<std::string, std::string>& params,
Davide Pesavento0dc02012021-11-23 22:55:03 -050070 ndn::KeyChain& keyChain, const Name& issuedCertName,
71 const std::array<uint8_t, 16>& nonce);
Zhiyi Zhangead9f002020-10-03 15:42:52 -070072
73 // challenge parameters
74 static const std::string PARAMETER_KEY_CREDENTIAL_CERT;
tylerliuf51e3162020-12-20 19:22:59 -080075 static const std::string PARAMETER_KEY_NONCE;
76 static const std::string PARAMETER_KEY_PROOF;
77 static const std::string NEED_PROOF;
Zhiyi Zhangead9f002020-10-03 15:42:52 -070078
tylerliudd359912020-10-20 13:05:22 -070079NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070080 void
81 parseConfigFile();
82
tylerliudd359912020-10-20 13:05:22 -070083NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Davide Pesavento0dc02012021-11-23 22:55:03 -050084 std::list<Certificate> m_trustAnchors;
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070085 std::string m_configFile;
86};
87
88} // namespace ndncert
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070089
tylerliuf51e3162020-12-20 19:22:59 -080090#endif // NDNCERT_CHALLENGE_POSSESSION_HPP