blob: 8eef944706f91c4470d7ec5aa48836e51c1d1d0c [file] [log] [blame]
Zhiyi Zhang65ba9322017-01-19 14:15:03 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -07003 * Copyright (c) 2017-2019, 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
24#include "../challenge-module.hpp"
25#include <ndn-cxx/util/time.hpp>
26
27namespace ndn {
28namespace ndncert {
29
30/**
31 * @brief Provide PIN code based challenge
32 *
33 * @sa https://github.com/named-data/ndncert/wiki/NDN-Certificate-Management-Protocol
34 *
35 * The main process of this challenge module is:
36 * 1. End entity provides empty string. The first POLL is only for selection.
37 * 2. The challenge module will generate a PIN code in ChallengeDefinedField.
38 * 3. End entity provides the verification code from some way to challenge module.
39 *
40 * There are four specific status defined in this challenge:
41 * NEED_CODE: When selection is made.
42 * WRONG_CODE: Get wrong verification code but still with secret lifetime and max retry times.
Zhiyi Zhanga9bda732017-05-20 22:58:55 -070043 *
44 * Failure info when application fails:
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080045 * FAILURE_TIMEOUT: When secret is out-dated.
46 * FAILURE_MAXRETRY: When requester tries too many times.
47 */
48class ChallengePin : public ChallengeModule
49{
50public:
51 ChallengePin(const size_t& maxAttemptTimes = 3,
52 const time::seconds& secretLifetime = time::seconds(3600));
53
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 Zhang65ba9322017-01-19 14:15:03 -080059 JsonSection
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070060 getRequirementForChallenge(int status, const std::string& challengeStatus) override;
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080061
62 JsonSection
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070063 genChallengeRequestJson(int status, const std::string& challengeStatus, const JsonSection& params) override;
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080064
65PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070066 // challenge status
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080067 static const std::string NEED_CODE;
68 static const std::string WRONG_CODE;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070069 // JSON attribute
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080070 static const std::string JSON_PIN_CODE;
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080071
72private:
73 time::seconds m_secretLifetime;
74 int m_maxAttemptTimes;
75};
76
77} // namespace ndncert
78} // namespace ndn
79
80#endif // NDNCERT_CHALLENGE_PIN_HPP