Zhiyi Zhang | 65ba932 | 2017-01-19 14:15:03 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2020, Regents of the University of California. |
Zhiyi Zhang | 65ba932 | 2017-01-19 14:15:03 -0800 | [diff] [blame] | 4 | * |
| 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 Zhang | dbd9d43 | 2020-10-07 15:56:27 -0700 | [diff] [blame] | 24 | #include "challenge-module.hpp" |
Zhiyi Zhang | 65ba932 | 2017-01-19 14:15:03 -0800 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace ndncert { |
| 28 | |
| 29 | /** |
| 30 | * @brief Provide PIN code based challenge |
| 31 | * |
| 32 | * @sa https://github.com/named-data/ndncert/wiki/NDN-Certificate-Management-Protocol |
| 33 | * |
| 34 | * The main process of this challenge module is: |
| 35 | * 1. End entity provides empty string. The first POLL is only for selection. |
| 36 | * 2. The challenge module will generate a PIN code in ChallengeDefinedField. |
| 37 | * 3. End entity provides the verification code from some way to challenge module. |
| 38 | * |
| 39 | * There are four specific status defined in this challenge: |
| 40 | * NEED_CODE: When selection is made. |
| 41 | * WRONG_CODE: Get wrong verification code but still with secret lifetime and max retry times. |
Zhiyi Zhang | a9bda73 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 42 | * |
| 43 | * Failure info when application fails: |
Zhiyi Zhang | 65ba932 | 2017-01-19 14:15:03 -0800 | [diff] [blame] | 44 | * FAILURE_TIMEOUT: When secret is out-dated. |
| 45 | * FAILURE_MAXRETRY: When requester tries too many times. |
| 46 | */ |
| 47 | class ChallengePin : public ChallengeModule |
| 48 | { |
| 49 | public: |
| 50 | ChallengePin(const size_t& maxAttemptTimes = 3, |
| 51 | const time::seconds& secretLifetime = time::seconds(3600)); |
| 52 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 53 | // For CA |
Zhiyi Zhang | aafc55e | 2020-09-28 17:54:48 -0700 | [diff] [blame] | 54 | std::tuple<ErrorCode, std::string> |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 55 | handleChallengeRequest(const Block& params, ca::RequestState& request) override; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 56 | |
| 57 | // For Client |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 58 | std::multimap<std::string, std::string> |
Zhiyi Zhang | 4604983 | 2020-09-28 17:08:12 -0700 | [diff] [blame] | 59 | getRequestedParameterList(Status status, const std::string& challengeStatus) override; |
Zhiyi Zhang | 65ba932 | 2017-01-19 14:15:03 -0800 | [diff] [blame] | 60 | |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 61 | Block |
Zhiyi Zhang | 4604983 | 2020-09-28 17:08:12 -0700 | [diff] [blame] | 62 | genChallengeRequestTLV(Status status, const std::string& challengeStatus, |
tylerliu | f2e6bb5 | 2020-12-13 13:23:05 -0800 | [diff] [blame] | 63 | const std::multimap<std::string, std::string>& params) override; |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 64 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 65 | // challenge status |
Zhiyi Zhang | 65ba932 | 2017-01-19 14:15:03 -0800 | [diff] [blame] | 66 | static const std::string NEED_CODE; |
| 67 | static const std::string WRONG_CODE; |
Zhiyi Zhang | 4604983 | 2020-09-28 17:08:12 -0700 | [diff] [blame] | 68 | // parameters |
| 69 | static const std::string PARAMETER_KEY_CODE; |
Zhiyi Zhang | 65ba932 | 2017-01-19 14:15:03 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | } // namespace ndncert |
| 73 | } // namespace ndn |
| 74 | |
| 75 | #endif // NDNCERT_CHALLENGE_PIN_HPP |