blob: 5d4a93ca1be2a6e4774860c9fa9e9b299cfb903d [file] [log] [blame]
Zhiyi Zhang0a89b722017-04-28 17:56:01 -07001/**
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -07002 * Copyright (c) 2017-2019, 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
23#include "../challenge-module.hpp"
24
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
55 void
56 handleChallengeRequest(const JsonSection& params, CertificateRequest& request) override;
57
58 // For Client
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070059 JsonSection
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070060 getRequirementForChallenge(int status, const std::string& challengeStatus) override;
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070061
62 JsonSection
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070063 genChallengeRequestJson(int status, const std::string& challengeStatus, const JsonSection& params) override;
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070064
65PUBLIC_WITH_TESTS_ELSE_PRIVATE:
66 void
67 parseConfigFile();
68
69PUBLIC_WITH_TESTS_ELSE_PRIVATE:
70 static const std::string FAILURE_INVALID_CREDENTIAL;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070071 static const std::string FAILURE_INVALID_FORMAT_CREDENTIAL;
72 static const std::string FAILURE_INVALID_FORMAT_SELF_SIGNED;
Zhiyi Zhang70fe2582017-05-19 15:01:03 -070073 static const std::string JSON_CREDENTIAL_CERT;
74 static const std::string JSON_CREDENTIAL_SELF;
Zhiyi Zhang0a89b722017-04-28 17:56:01 -070075
76PUBLIC_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