add email sending script
refs: #4053
Change-Id: I1ffe550b20e7fe394fb7f25d71eafa61d4a8fc6f
diff --git a/src/challenge-module/challenge-email.cpp b/src/challenge-module/challenge-email.cpp
index fc25d8c..c63961c 100644
--- a/src/challenge-module/challenge-email.cpp
+++ b/src/challenge-module/challenge-email.cpp
@@ -65,7 +65,7 @@
}
std::string emailCode = generateSecretCode();
- sendEmail(emailAddress, emailCode);
+ sendEmail(emailAddress, emailCode, request.getCaName().toUri());
request.setStatus(NEED_CODE);
request.setChallengeType(CHALLENGE_TYPE);
@@ -185,30 +185,17 @@
}
void
-ChallengeEmail::sendEmail(const std::string& emailAddress, const std::string& secret) const
+ChallengeEmail::sendEmail(const std::string& emailAddress, const std::string& secret,
+ const std::string& caName) const
{
- pid_t pid = fork();
-
- if (pid < 0) {
- _LOG_TRACE("Cannot fork before trying to call email sending script");
+ std::string command = m_sendEmailScript;
+ command += " \"" + emailAddress + "\" \"" + secret + "\" \"" + caName + "\"";
+ int result = system(command.c_str());
+ if (result == -1) {
+ _LOG_TRACE("EmailSending Script " + m_sendEmailScript + " fails.");
}
- else if (pid == 0) {
- int ret;
- std::vector<char> emailParam(emailAddress.begin(), emailAddress.end());
- emailParam.push_back('\0');
-
- std::vector<char> secretParam(secret.begin(), secret.end());
- secretParam.push_back('\0');
-
- std::vector<char> defaultParam(m_sendEmailScript.begin(), m_sendEmailScript.end());
- defaultParam.push_back('\0');
-
- char* argv[] = {&defaultParam[0], &emailParam[0], &secretParam[0], nullptr};
- ret = execve(m_sendEmailScript.c_str(), argv, nullptr);
-
- BOOST_THROW_EXCEPTION(Error("Email sending script went wrong, error code: " + std::to_string(ret)));
- }
-
+ _LOG_TRACE("EmailSending Script " + m_sendEmailScript +
+ " was executed successfully with return value" + std::to_string(result) + ".");
return;
}
diff --git a/src/challenge-module/challenge-email.hpp b/src/challenge-module/challenge-email.hpp
index 0f0d935..a014d00 100644
--- a/src/challenge-module/challenge-email.hpp
+++ b/src/challenge-module/challenge-email.hpp
@@ -30,7 +30,10 @@
/**
* @brief Provide Email based challenge
*
+ * For challenge design
* @sa https://github.com/named-data/ndncert/wiki/NDN-Certificate-Management-Protocol
+ * For deployment instructions:
+ * @sa https://github.com/named-data/ndncert/wiki/Deploy-Email-Challenge
*
* The main process of this challenge module is:
* 1. Requester provides its email address.
@@ -49,7 +52,7 @@
class ChallengeEmail : public ChallengeModule
{
public:
- ChallengeEmail(const std::string& scriptPath = "send-mail.sh",
+ ChallengeEmail(const std::string& scriptPath = "ndncert-send-email-challenge",
const size_t& maxAttemptTimes = 3,
const time::seconds secretLifetime = time::minutes(20));
@@ -79,7 +82,8 @@
isValidEmailAddress(const std::string& emailAddress);
void
- sendEmail(const std::string& emailAddress, const std::string& secret) const;
+ sendEmail(const std::string& emailAddress, const std::string& secret,
+ const std::string& caName) const;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
static std::tuple<time::system_clock::TimePoint, std::string, int>
diff --git a/src/client-module.cpp b/src/client-module.cpp
index 67c6201..9994c31 100644
--- a/src/client-module.cpp
+++ b/src/client-module.cpp
@@ -94,7 +94,7 @@
certRequest.setName(Name(state->m_key.getName()).append("cert-request").appendVersion());
certRequest.setContentType(tlv::ContentType_Key);
certRequest.setFreshnessPeriod(time::hours(24));
- certRequest.setContent(state->m_key.getPublicKey().get<uint8_t>(), state->m_key.getPublicKey().size());
+ certRequest.setContent(state->m_key.getPublicKey().data(), state->m_key.getPublicKey().size());
SignatureInfo signatureInfo;
signatureInfo.setValidityPeriod(security::ValidityPeriod(time::system_clock::now(),
time::system_clock::now() + time::days(10)));