blob: f853e9538e177f40ec44039a1564ee57a10db8e3 [file] [log] [blame]
Zhiyi Zhangdefa9592017-02-21 10:56:22 -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 Zhangdefa9592017-02-21 10:56:22 -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_EMAIL_HPP
22#define NDNCERT_CHALLENGE_EMAIL_HPP
23
24#include "../challenge-module.hpp"
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080025
26namespace ndn {
27namespace ndncert {
28
29/**
30 * @brief Provide Email based challenge
31 *
Zhiyi Zhang576aad12017-10-03 15:41:53 -070032 * For challenge design
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080033 * @sa https://github.com/named-data/ndncert/wiki/NDN-Certificate-Management-Protocol
Zhiyi Zhang576aad12017-10-03 15:41:53 -070034 * For deployment instructions:
35 * @sa https://github.com/named-data/ndncert/wiki/Deploy-Email-Challenge
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080036 *
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 Zhanga9bda732017-05-20 22:58:55 -070045 *
46 * Failure info when application fails:
47 * FAILURE_MAXRETRY: When run out retry times.
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080048 * FAILURE_INVALID_EMAIL: When the email is invalid.
49 * FAILURE_TIMEOUT: When the secret lifetime expires.
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080050 */
51class ChallengeEmail : public ChallengeModule
52{
53public:
Zhiyi Zhang576aad12017-10-03 15:41:53 -070054 ChallengeEmail(const std::string& scriptPath = "ndncert-send-email-challenge",
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080055 const size_t& maxAttemptTimes = 3,
56 const time::seconds secretLifetime = time::minutes(20));
57
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070058 // For CA
Zhiyi Zhangaafc55e2020-09-28 17:54:48 -070059 std::tuple<ErrorCode, std::string>
Zhiyi Zhange232a742020-09-29 17:34:17 -070060 handleChallengeRequest(const Block& params, RequestState& request) override;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070061
62 // For Client
Zhiyi Zhang46049832020-09-28 17:08:12 -070063 std::vector<std::tuple<std::string, std::string>>
64 getRequestedParameterList(Status status, const std::string& challengeStatus) override;
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080065
Suyong Won19fba4d2020-05-09 13:39:46 -070066 Block
Zhiyi Zhang46049832020-09-28 17:08:12 -070067 genChallengeRequestTLV(Status status, const std::string& challengeStatus,
68 std::vector<std::tuple<std::string, std::string>>&& params) override;
Suyong Won19fba4d2020-05-09 13:39:46 -070069
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080070PUBLIC_WITH_TESTS_ELSE_PRIVATE:
71 static bool
72 isValidEmailAddress(const std::string& emailAddress);
73
74 void
Zhiyi Zhang576aad12017-10-03 15:41:53 -070075 sendEmail(const std::string& emailAddress, const std::string& secret,
Zhiyi Zhange232a742020-09-29 17:34:17 -070076 const RequestState& request) const;
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080077
78PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070079 // challenge status
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080080 static const std::string NEED_CODE;
81 static const std::string WRONG_CODE;
Zhiyi Zhang46049832020-09-28 17:08:12 -070082 // parameters
83 static const std::string PARAMETER_KEY_EMAIL;
84 static const std::string PARAMETER_KEY_CODE;
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080085
86private:
87 std::string m_sendEmailScript;
88 int m_maxAttemptTimes;
89 time::seconds m_secretLifetime;
90};
91
92} // namespace ndncert
93} // namespace ndn
94
95#endif // NDNCERT_CHALLENGE_EMAIL_HPP