blob: d9d4bf43944a1cf7f84b3dd5fbf01717846ff8dc [file] [log] [blame]
Zhiyi Zhangdefa9592017-02-21 10:56:22 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento0dc02012021-11-23 22:55:03 -05002/*
Tianyuan Yu13aac732022-03-03 20:59:54 -08003 * Copyright (c) 2017-2022, 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
Zhiyi Zhangdbd9d432020-10-07 15:56:27 -070024#include "challenge-module.hpp"
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080025
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080026namespace ndncert {
27
28/**
Davide Pesavento0251aae2022-07-09 21:05:04 -040029 * @brief Provide email-based challenge.
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080030 *
31 * The main process of this challenge module is:
32 * 1. Requester provides its email address.
33 * 2. The challenge module will send a verification code to this email address.
34 * 3. Requester provides the verification code to challenge module.
35 *
36 * There are several challenge status in EMAIL challenge:
37 * NEED_CODE: When email address is provided and the verification code has been sent out.
38 * WRONG_CODE: Wrong code but still within secret lifetime and within max try times.
Zhiyi Zhanga9bda732017-05-20 22:58:55 -070039 *
40 * Failure info when application fails:
41 * FAILURE_MAXRETRY: When run out retry times.
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080042 * FAILURE_TIMEOUT: When the secret lifetime expires.
Davide Pesavento0251aae2022-07-09 21:05:04 -040043 *
44 * @sa https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3-Challenges
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080045 */
46class ChallengeEmail : public ChallengeModule
47{
48public:
Zhiyi Zhang576aad12017-10-03 15:41:53 -070049 ChallengeEmail(const std::string& scriptPath = "ndncert-send-email-challenge",
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080050 const size_t& maxAttemptTimes = 3,
Zhiyi Zhangead9f002020-10-03 15:42:52 -070051 const time::seconds secretLifetime = time::seconds(300));
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080052
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070053 // For CA
Zhiyi Zhangaafc55e2020-09-28 17:54:48 -070054 std::tuple<ErrorCode, std::string>
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070055 handleChallengeRequest(const Block& params, ca::RequestState& request) override;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070056
57 // For Client
tylerliu40226332020-11-11 15:37:16 -080058 std::multimap<std::string, std::string>
Zhiyi Zhang46049832020-09-28 17:08:12 -070059 getRequestedParameterList(Status status, const std::string& challengeStatus) override;
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080060
Suyong Won19fba4d2020-05-09 13:39:46 -070061 Block
Zhiyi Zhang46049832020-09-28 17:08:12 -070062 genChallengeRequestTLV(Status status, const std::string& challengeStatus,
tylerliuf2e6bb52020-12-13 13:23:05 -080063 const std::multimap<std::string, std::string>& params) override;
Suyong Won19fba4d2020-05-09 13:39:46 -070064
Zhiyi Zhangead9f002020-10-03 15:42:52 -070065 // challenge status
66 static const std::string NEED_CODE;
67 static const std::string WRONG_CODE;
Zhiyi Zhangead9f002020-10-03 15:42:52 -070068 // challenge parameters
69 static const std::string PARAMETER_KEY_EMAIL;
70 static const std::string PARAMETER_KEY_CODE;
71
tylerliudd359912020-10-20 13:05:22 -070072NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080073 static bool
74 isValidEmailAddress(const std::string& emailAddress);
75
76 void
Zhiyi Zhang576aad12017-10-03 15:41:53 -070077 sendEmail(const std::string& emailAddress, const std::string& secret,
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070078 const ca::RequestState& request) const;
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080079
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080080private:
81 std::string m_sendEmailScript;
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080082};
83
84} // namespace ndncert
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080085
86#endif // NDNCERT_CHALLENGE_EMAIL_HPP