#include <libcitadel.h>
#include "../../config.h"
#include "../../msgbase.h"
+#include "smtp_util.h"
// Generate a private key and selector for DKIM if needed. This is called during server startup.
"\r\n"
),0);
- ptr = inetcfg_in;
- while (ptr && *ptr) {
- char *sep = strchr(ptr, '|');
- if (sep && !strncasecmp(sep+1, HKEY("localhost"))) {
- StrBufAppendPrintf(message, "Host name : %s._domainkey.", CtdlGetConfigStr("dkim_selector"));
- StrBufAppendBufPlain(message, ptr, sep-ptr, 0);
- StrBufAppendBufPlain(message, HKEY("\r\n"), 0);
- StrBufAppendPrintf(message, "Record type: TXT\r\n");
- StrBufAppendBufPlain(message, HKEY("Value : v=DKIM1;k=rsa;p="), 0);
-
- // FIXME calculate the public key and add it here
+ char *pubkey = NULL;
+ EVP_PKEY *pkey = dkim_import_key(CtdlGetConfigStr("dkim_private_key"));
+ if (pkey) {
+ pubkey = dkim_get_public_key(pkey);
+ EVP_PKEY_free(pkey);
+ }
- StrBufAppendPrintf(message, "\r\n\r\n");
- }
- ptr = strchr(ptr, '\n');
- if (ptr) {
- ++ptr;
+ if (pubkey) {
+ ptr = inetcfg_in;
+ while (ptr && *ptr) {
+ char *sep = strchr(ptr, '|');
+ if (sep && !strncasecmp(sep+1, HKEY("localhost"))) {
+ StrBufAppendPrintf(message, "Host name : %s._domainkey.", CtdlGetConfigStr("dkim_selector"));
+ StrBufAppendBufPlain(message, ptr, sep-ptr, 0);
+ StrBufAppendBufPlain(message, HKEY("\r\n"), 0);
+ StrBufAppendPrintf(message, "Record type: TXT\r\n");
+ StrBufAppendPrintf(message, "Value : v=DKIM1;k=rsa;p=%s\r\n", pubkey);
+ StrBufAppendPrintf(message, "\r\n");
+ }
+ ptr = strchr(ptr, '\n');
+ if (ptr) {
+ ++ptr;
+ }
}
+ free(pubkey);
+ }
+ else {
+ StrBufAppendBufPlain(message, HKEY("YOW! Something went wrong.\r\n\r\n"), 0);
}
quickie_message("Citadel",