blob: cfcf508b4931d7c8856de373b6ee13cee79e9f65 [file] [log] [blame]
Zhiyi Zhang65ba9322017-01-19 14:15:03 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento0dc02012021-11-23 22:55:03 -05002/*
3 * Copyright (c) 2017-2021, Regents of the University of California.
Zhiyi Zhang65ba9322017-01-19 14:15:03 -08004 *
5 * This file is part of ndncert, a certificate management system based on NDN.
6 *
7 * ndncert is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License along with
16 * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ndncert authors and contributors.
19 */
20
21#ifndef NDNCERT_CHALLENGE_PIN_HPP
22#define NDNCERT_CHALLENGE_PIN_HPP
23
Zhiyi Zhangdbd9d432020-10-07 15:56:27 -070024#include "challenge-module.hpp"
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080025
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080026namespace ndncert {
27
28/**
29 * @brief Provide PIN code based challenge
30 *
31 * @sa https://github.com/named-data/ndncert/wiki/NDN-Certificate-Management-Protocol
32 *
33 * The main process of this challenge module is:
34 * 1. End entity provides empty string. The first POLL is only for selection.
35 * 2. The challenge module will generate a PIN code in ChallengeDefinedField.
36 * 3. End entity provides the verification code from some way to challenge module.
37 *
38 * There are four specific status defined in this challenge:
39 * NEED_CODE: When selection is made.
40 * WRONG_CODE: Get wrong verification code but still with secret lifetime and max retry times.
Zhiyi Zhanga9bda732017-05-20 22:58:55 -070041 *
42 * Failure info when application fails:
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080043 * FAILURE_TIMEOUT: When secret is out-dated.
44 * FAILURE_MAXRETRY: When requester tries too many times.
45 */
46class ChallengePin : public ChallengeModule
47{
48public:
49 ChallengePin(const size_t& maxAttemptTimes = 3,
50 const time::seconds& secretLifetime = time::seconds(3600));
51
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070052 // For CA
Zhiyi Zhangaafc55e2020-09-28 17:54:48 -070053 std::tuple<ErrorCode, std::string>
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070054 handleChallengeRequest(const Block& params, ca::RequestState& request) override;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070055
56 // For Client
tylerliu40226332020-11-11 15:37:16 -080057 std::multimap<std::string, std::string>
Zhiyi Zhang46049832020-09-28 17:08:12 -070058 getRequestedParameterList(Status status, const std::string& challengeStatus) override;
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080059
Suyong Won19fba4d2020-05-09 13:39:46 -070060 Block
Zhiyi Zhang46049832020-09-28 17:08:12 -070061 genChallengeRequestTLV(Status status, const std::string& challengeStatus,
tylerliuf2e6bb52020-12-13 13:23:05 -080062 const std::multimap<std::string, std::string>& params) override;
Suyong Won19fba4d2020-05-09 13:39:46 -070063
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070064 // challenge status
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080065 static const std::string NEED_CODE;
66 static const std::string WRONG_CODE;
Zhiyi Zhang46049832020-09-28 17:08:12 -070067 // parameters
68 static const std::string PARAMETER_KEY_CODE;
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080069};
70
71} // namespace ndncert
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080072
73#endif // NDNCERT_CHALLENGE_PIN_HPP