]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/modules/smtp/dkim_bindings.c
Complete: post Aide message when DKIM records need to be updated
[citadel.git] / citadel / server / modules / smtp / dkim_bindings.c
index e7491c15468c52da4897802eb747e822fc47d505..340e574b669a21c52672986cea1b890afff63c62 100644 (file)
@@ -29,6 +29,7 @@
 #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.
@@ -144,24 +145,34 @@ void dkim_check_advisory(char *inetcfg_in) {
                        "\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",