send-email-challenge: improve default email templates
And use built-in interpolation of ConfigParser
Change-Id: Ifb534d1a49a6ab4fcbd08b49082e8676646797c6
diff --git a/ndncert-mail.conf.sample b/ndncert-mail.conf.sample
index 7731cf5..de7809b 100644
--- a/ndncert-mail.conf.sample
+++ b/ndncert-mail.conf.sample
@@ -6,7 +6,20 @@
SMTP_PASSWORD = leave it empty if you do not have one
[ndncert.email]
-MAIL_FROM = NDN Testbed Certificate Robot <noreply-ndncert@named-data.net>
-SUBJECT = Email Challenge Triggered by NDNCERT
-TEXT_TEMPLATE = Your PIN code: {0} from NDNCERT CA {1}. Certificate Name: {2}. Your email has been used to apply for a digital certificate from NDNCERT. Please keep it secret and type it in your application to complete the certificate issuance process. If you do not know what is going on, please ignore this message.
-HTML_TEMPLATE = <html><head></head><body><p><b>Your PIN code: {0} from NDNCERT CA {1}. Certificate Name: {2}.</b></p><p>Your email has been used to apply for a digital certificate from NDNCERT. Please keep it secret and type it in your application to complete the certificate issuance process. If you do not know what is going on, please ignore this message.</p><p>Sincerely,<br/>NDN Testbed NDNCERT robot</p>
+from = NDN Certificate Robot <noreply@ndncert.named-data.net>
+subject = Your NDNCERT verification code
+text_template = Your email was recently used to apply for a digital certificate from NDNCERT.
+ Here is the verification code to enter into your application and complete the certificate issuance process. Do not share this code with anyone else.
+
+ Your verification code is: ${secret}
+ CA name: ${ca_name}
+ Certificate name: ${cert_name}
+
+ If you do not know what is going on, please ignore this message.
+html_template = <!DOCTYPE html>
+ <p>Your email was recently used to apply for a digital certificate from NDNCERT.<br>
+ Here is the verification code to enter into your application and complete the certificate issuance process. Do not share this code with anyone else.</p>
+ <p><strong>Your verification code is: <code>${secret}</code></strong><br>
+ CA name: <code>${ca_name}</code><br>
+ Certificate name: <code>${cert_name}</code></p>
+ <p>If you do not know what is going on, please ignore this message.</p>
diff --git a/ndncert-send-email-challenge.py b/ndncert-send-email-challenge.py
index a220f92..00aae82 100755
--- a/ndncert-send-email-challenge.py
+++ b/ndncert-send-email-challenge.py
@@ -6,14 +6,22 @@
# init arg parser and parse
parser = argparse.ArgumentParser(description='Email challenge sender for NDNCERT CA')
-parser.add_argument('email', help='email address of the recipient')
+parser.add_argument('recipient', help='email address of the recipient')
parser.add_argument('secret', help='secret code for the challenge')
parser.add_argument('ca_name', help='name of the certificate authority')
parser.add_argument('cert_name', help='name of the certificate being requested')
args = parser.parse_args()
+vars = {
+ 'ca_name': args.ca_name,
+ 'cert_name': args.cert_name,
+ 'recipient': args.recipient,
+ 'secret': args.secret,
+}
+
# open config file
-confParser = configparser.ConfigParser()
+confParser = configparser.ConfigParser(empty_lines_in_values=True,
+ interpolation=configparser.ExtendedInterpolation())
confParser.read('@SYSCONFDIR@/ndncert/ndncert-mail.conf')
# read smtp settings
@@ -24,15 +32,15 @@
password = confParser.get('ndncert.smtp', 'smtp_password')
# read email settings
-from_addr = confParser.get('ndncert.email', 'mail_from')
-subject = confParser.get('ndncert.email', 'subject')
-text = confParser.get('ndncert.email', 'text_template').format(args.secret, args.ca_name, args.cert_name)
-html = confParser.get('ndncert.email', 'html_template').format(args.secret, args.ca_name, args.cert_name)
+from_addr = confParser.get('ndncert.email', 'from', vars=vars)
+subject = confParser.get('ndncert.email', 'subject', vars=vars)
+text = confParser.get('ndncert.email', 'text_template', vars=vars)
+html = confParser.get('ndncert.email', 'html_template', vars=vars)
# create email message
msg = EmailMessage()
msg['From'] = from_addr
-msg['To'] = args.email
+msg['To'] = args.recipient
msg['Subject'] = subject
msg.set_content(text)
msg.add_alternative(html, subtype='html')
diff --git a/src/challenge/challenge-email.cpp b/src/challenge/challenge-email.cpp
index 26d42f5..d6765a3 100644
--- a/src/challenge/challenge-email.cpp
+++ b/src/challenge/challenge-email.cpp
@@ -72,7 +72,7 @@
if (request.challengeState->challengeStatus == NEED_CODE ||
request.challengeState->challengeStatus == WRONG_CODE) {
NDN_LOG_TRACE("Challenge status: " << request.challengeState->challengeStatus);
- // the incoming interest should bring the pin code
+ // the incoming interest should bring the verification code
std::string givenCode = readString(params.get(tlv::ParameterValue));
auto secret = request.challengeState->secrets;
// check if run out of time