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 | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2019, 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 | |
| 24 | #include "../challenge-module.hpp" |
| 25 | #include <ndn-cxx/util/time.hpp> |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace ndncert { |
| 29 | |
| 30 | /** |
| 31 | * @brief Provide Email based challenge |
| 32 | * |
Zhiyi Zhang | 576aad1 | 2017-10-03 15:41:53 -0700 | [diff] [blame] | 33 | * For challenge design |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 34 | * @sa https://github.com/named-data/ndncert/wiki/NDN-Certificate-Management-Protocol |
Zhiyi Zhang | 576aad1 | 2017-10-03 15:41:53 -0700 | [diff] [blame] | 35 | * For deployment instructions: |
| 36 | * @sa https://github.com/named-data/ndncert/wiki/Deploy-Email-Challenge |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 37 | * |
| 38 | * The main process of this challenge module is: |
| 39 | * 1. Requester provides its email address. |
| 40 | * 2. The challenge module will send a verification code to this email address. |
| 41 | * 3. Requester provides the verification code to challenge module. |
| 42 | * |
| 43 | * There are several challenge status in EMAIL challenge: |
| 44 | * NEED_CODE: When email address is provided and the verification code has been sent out. |
| 45 | * 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] | 46 | * |
| 47 | * Failure info when application fails: |
| 48 | * FAILURE_MAXRETRY: When run out retry times. |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 49 | * FAILURE_INVALID_EMAIL: When the email is invalid. |
| 50 | * FAILURE_TIMEOUT: When the secret lifetime expires. |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 51 | */ |
| 52 | class ChallengeEmail : public ChallengeModule |
| 53 | { |
| 54 | public: |
Zhiyi Zhang | 576aad1 | 2017-10-03 15:41:53 -0700 | [diff] [blame] | 55 | ChallengeEmail(const std::string& scriptPath = "ndncert-send-email-challenge", |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 56 | const size_t& maxAttemptTimes = 3, |
| 57 | const time::seconds secretLifetime = time::minutes(20)); |
| 58 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 59 | // For CA |
| 60 | void |
| 61 | handleChallengeRequest(const JsonSection& params, CertificateRequest& request) override; |
| 62 | |
| 63 | // For Client |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 64 | JsonSection |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 65 | getRequirementForChallenge(int status, const std::string& challengeStatus) override; |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 66 | |
| 67 | JsonSection |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 68 | genChallengeRequestJson(int status, const std::string& challengeStatus, const JsonSection& params) override; |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 69 | |
| 70 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 71 | static bool |
| 72 | isValidEmailAddress(const std::string& emailAddress); |
| 73 | |
| 74 | void |
Zhiyi Zhang | 576aad1 | 2017-10-03 15:41:53 -0700 | [diff] [blame] | 75 | sendEmail(const std::string& emailAddress, const std::string& secret, |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 76 | const CertificateRequest& request) const; |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 77 | |
| 78 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 79 | // challenge status |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 80 | static const std::string NEED_CODE; |
| 81 | static const std::string WRONG_CODE; |
Zhiyi Zhang | a9bda73 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 82 | static const std::string FAILURE_INVALID_EMAIL; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 83 | // JSON attribute |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 84 | static const std::string JSON_EMAIL; |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 85 | static const std::string JSON_CODE; |
Zhiyi Zhang | defa959 | 2017-02-21 10:56:22 -0800 | [diff] [blame] | 86 | |
| 87 | private: |
| 88 | std::string m_sendEmailScript; |
| 89 | int m_maxAttemptTimes; |
| 90 | time::seconds m_secretLifetime; |
| 91 | }; |
| 92 | |
| 93 | } // namespace ndncert |
| 94 | } // namespace ndn |
| 95 | |
| 96 | #endif // NDNCERT_CHALLENGE_EMAIL_HPP |