&& !IsEmptyStr(dkim_private_key) // Do we have a private signing key?
&& !IsEmptyStr(dkim_selector) // and a selector to go with it?
) {
- char *pkey = strdup(dkim_private_key); // If you answered "yes" to all of the above questions,
- if (pkey) { // congratulations! We get to DKIM-sign the message!
- char *sp;
- while (sp = strchr(pkey, '_')) { // The dkim_private_key record contains our RSA private key,
- *sp = '\n'; // but we have to convert all the newlines back to underscores.
- }
- syslog(LOG_DEBUG, "smtpclient: dkim-signing with private key for selector <%s> domain <%s>",
- dkim_selector, dkim_from_domain);
- dkim_sign(s.TheMessage, pkey, dkim_from_domain, dkim_selector);
- free(pkey);
- }
+ // If you answered "yes" to all of the above questions, congratulations! We get to sign the message!
+ syslog(LOG_DEBUG, "smtpclient: dkim-signing for selector <%s> in domain <%s>", dkim_selector, dkim_from_domain);
+
+ // Remember, the dkim_sign() function is capable of handling a PEM-encoded PKCS#7 private key that
+ // has had all of its newlines replaced by underscores -- which is exactly how we store it.
+ dkim_sign(s.TheMessage,dkim_private_key, dkim_from_domain, dkim_selector);
}
// Prepare the buffer for transmittal