blob: 72db98190e44ecec643584bc972f2b9fd5592b1b [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
20#ifndef NDNCERT_CHALLENGE_CREDENTIAL_HPP
21#define NDNCERT_CHALLENGE_CREDENTIAL_HPP
22
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/**
29 * @brief Provide Credential based challenge
30 *
31 * Credential here means the certificate issued by a trust anchor. Once the requester
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070032 * could proof his/her possession of an existing certificate from other certificate issuer,
33 * 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.
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070042 * 3. The content of the signed Data is the request id
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070043 *
Zhiyi Zhanga9bda732017-05-20 22:58:55 -070044 * 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 Zhang0a89b722017-04-28 17:56:01 -070048 */
49class ChallengeCredential : public ChallengeModule
50{
51public:
Zhiyi Zhang70fe2582017-05-19 15:01:03 -070052 ChallengeCredential(const std::string& configPath = "");
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070053
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070054 // For CA
Zhiyi Zhangaafc55e2020-09-28 17:54:48 -070055 std::tuple<ErrorCode, std::string>
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070056 handleChallengeRequest(const Block& params, ca::RequestState& request) override;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070057
58 // For Client
Zhiyi Zhang46049832020-09-28 17:08:12 -070059 std::vector<std::tuple<std::string, std::string>>
60 getRequestedParameterList(Status status, const std::string& challengeStatus) override;
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070061
Suyong Won19fba4d2020-05-09 13:39:46 -070062 Block
Zhiyi Zhang46049832020-09-28 17:08:12 -070063 genChallengeRequestTLV(Status status, const std::string& challengeStatus,
64 std::vector<std::tuple<std::string, std::string>>&& params) override;
Suyong Won19fba4d2020-05-09 13:39:46 -070065
Zhiyi Zhangead9f002020-10-03 15:42:52 -070066 static void
67 fulfillParameters(std::vector<std::tuple<std::string, std::string>>& params,
Zhiyi Zhangc9ada1b2020-10-29 19:13:15 -070068 KeyChain& keyChain, const Name& issuedCertName, const RequestId& requestId);
Zhiyi Zhangead9f002020-10-03 15:42:52 -070069
70 // challenge parameters
71 static const std::string PARAMETER_KEY_CREDENTIAL_CERT;
72 static const std::string PARAMETER_KEY_PROOF_OF_PRIVATE_KEY;
73
tylerliudd359912020-10-20 13:05:22 -070074NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070075 void
76 parseConfigFile();
77
tylerliudd359912020-10-20 13:05:22 -070078NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
tylerliua7bea662020-10-08 18:51:02 -070079 std::list<security::Certificate> m_trustAnchors;
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070080 std::string m_configFile;
81};
82
83} // namespace ndncert
84} // namespace ndn
85
86#endif // NDNCERT_CHALLENGE_CREDENTIAL_HPP