blob: 2f40f1fc8b7e0e65ce3d93facd8a8130ad888b97 [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"
25#include <ndn-cxx/util/time.hpp>
26
27namespace ndn {
28namespace ndncert {
29
30/**
31 * @brief Provide Email based challenge
32 *
Zhiyi Zhang576aad12017-10-03 15:41:53 -070033 * For challenge design
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080034 * @sa https://github.com/named-data/ndncert/wiki/NDN-Certificate-Management-Protocol
Zhiyi Zhang576aad12017-10-03 15:41:53 -070035 * For deployment instructions:
36 * @sa https://github.com/named-data/ndncert/wiki/Deploy-Email-Challenge
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080037 *
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 Zhanga9bda732017-05-20 22:58:55 -070046 *
47 * Failure info when application fails:
48 * FAILURE_MAXRETRY: When run out retry times.
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080049 * FAILURE_INVALID_EMAIL: When the email is invalid.
50 * FAILURE_TIMEOUT: When the secret lifetime expires.
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080051 */
52class ChallengeEmail : public ChallengeModule
53{
54public:
Zhiyi Zhang576aad12017-10-03 15:41:53 -070055 ChallengeEmail(const std::string& scriptPath = "ndncert-send-email-challenge",
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080056 const size_t& maxAttemptTimes = 3,
57 const time::seconds secretLifetime = time::minutes(20));
58
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070059 // For CA
60 void
61 handleChallengeRequest(const JsonSection& params, CertificateRequest& request) override;
62
63 // For Client
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080064 JsonSection
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070065 getRequirementForChallenge(int status, const std::string& challengeStatus) override;
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080066
67 JsonSection
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070068 genChallengeRequestJson(int status, const std::string& challengeStatus, const JsonSection& params) override;
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080069
70PUBLIC_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 Zhangaf7c2902019-03-14 22:13:21 -070076 const CertificateRequest& 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 Zhanga9bda732017-05-20 22:58:55 -070082 static const std::string FAILURE_INVALID_EMAIL;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070083 // JSON attribute
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080084 static const std::string JSON_EMAIL;
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080085 static const std::string JSON_CODE;
Zhiyi Zhangdefa9592017-02-21 10:56:22 -080086
87private:
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