Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -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 | defa959 | 2017-02-21 10:56:22 -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_EMAIL_HPP |
| 22 | #define NDNCERT_CHALLENGE_EMAIL_HPP |
| 23 | |
Zhiyi Zhang | dbd9d43 | 2020-10-07 15:56:27 -0700 | [diff] [blame] | 24 | #include "challenge-module.hpp" |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace ndncert { |
| 28 | |
| 29 | /** |
| 30 | * @brief Provide Email based challenge |
| 31 | * |
Zhiyi Zhang | 576aad1 | 2017-10-03 15:41:53 -0700 | [diff] [blame] | 32 | * For challenge design |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 33 | * @sa https://github.com/named-data/ndncert/wiki/NDN-Certificate-Management-Protocol |
Zhiyi Zhang | 576aad1 | 2017-10-03 15:41:53 -0700 | [diff] [blame] | 34 | * For deployment instructions: |
| 35 | * @sa https://github.com/named-data/ndncert/wiki/Deploy-Email-Challenge |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 36 | * |
| 37 | * The main process of this challenge module is: |
| 38 | * 1. Requester provides its email address. |
| 39 | * 2. The challenge module will send a verification code to this email address. |
| 40 | * 3. Requester provides the verification code to challenge module. |
| 41 | * |
| 42 | * There are several challenge status in EMAIL challenge: |
| 43 | * NEED_CODE: When email address is provided and the verification code has been sent out. |
| 44 | * WRONG_CODE: Wrong code but still within secret lifetime and within max try times. |
Zhiyi Zhang | a9bda73 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 45 | * |
| 46 | * Failure info when application fails: |
| 47 | * FAILURE_MAXRETRY: When run out retry times. |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 48 | * FAILURE_INVALID_EMAIL: When the email is invalid. |
| 49 | * FAILURE_TIMEOUT: When the secret lifetime expires. |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 50 | */ |
| 51 | class ChallengeEmail : public ChallengeModule |
| 52 | { |
| 53 | public: |
Zhiyi Zhang | 576aad1 | 2017-10-03 15:41:53 -0700 | [diff] [blame] | 54 | ChallengeEmail(const std::string& scriptPath = "ndncert-send-email-challenge", |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 55 | const size_t& maxAttemptTimes = 3, |
Zhiyi Zhang | ead9f00 | 2020-10-03 15:42:52 -0700 | [diff] [blame] | 56 | const time::seconds secretLifetime = time::seconds(300)); |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 57 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 58 | // For CA |
Zhiyi Zhang | aafc55e | 2020-09-28 17:54:48 -0700 | [diff] [blame] | 59 | std::tuple<ErrorCode, std::string> |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 60 | handleChallengeRequest(const Block& params, CaState& request) override; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 61 | |
| 62 | // For Client |
Zhiyi Zhang | 4604983 | 2020-09-28 17:08:12 -0700 | [diff] [blame] | 63 | std::vector<std::tuple<std::string, std::string>> |
| 64 | getRequestedParameterList(Status status, const std::string& challengeStatus) override; |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 65 | |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 66 | Block |
Zhiyi Zhang | 4604983 | 2020-09-28 17:08:12 -0700 | [diff] [blame] | 67 | genChallengeRequestTLV(Status status, const std::string& challengeStatus, |
| 68 | std::vector<std::tuple<std::string, std::string>>&& params) override; |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 69 | |
Zhiyi Zhang | ead9f00 | 2020-10-03 15:42:52 -0700 | [diff] [blame] | 70 | // challenge status |
| 71 | static const std::string NEED_CODE; |
| 72 | static const std::string WRONG_CODE; |
| 73 | static const std::string INVALID_EMAIL; |
| 74 | // challenge parameters |
| 75 | static const std::string PARAMETER_KEY_EMAIL; |
| 76 | static const std::string PARAMETER_KEY_CODE; |
| 77 | |
tylerliu | dd35991 | 2020-10-20 13:05:22 -0700 | [diff] [blame] | 78 | NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 79 | static bool |
| 80 | isValidEmailAddress(const std::string& emailAddress); |
| 81 | |
| 82 | void |
Zhiyi Zhang | 576aad1 | 2017-10-03 15:41:53 -0700 | [diff] [blame] | 83 | sendEmail(const std::string& emailAddress, const std::string& secret, |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 84 | const CaState& request) const; |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 85 | |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 86 | private: |
| 87 | std::string m_sendEmailScript; |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | } // namespace ndncert |
| 91 | } // namespace ndn |
| 92 | |
| 93 | #endif // NDNCERT_CHALLENGE_EMAIL_HPP |