]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Split long DKIM public keys
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 17 Jun 2017 14:08:15 +0000 (15:08 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 17 Jun 2017 14:08:15 +0000 (15:08 +0100)
Issue: #1676

src/rspamadm/dkim_keygen.c

index 42922ed355e53fbb99597e6b6d4affe20413225b..14a2e18f2d6d951c13d3d212942c1573dcd41f13 100644 (file)
@@ -81,6 +81,7 @@ rspamadm_dkim_keygen (gint argc, gchar **argv)
        EVP_PKEY *pk;
        gint rc;
        glong publen;
+       gsize b64_len;
        gchar *pubdata, *b64_data;
 
        context = g_option_context_new (
@@ -140,11 +141,33 @@ rspamadm_dkim_keygen (gint argc, gchar **argv)
        publen = BIO_get_mem_data (pubout, &pubdata);
 
        g_assert (publen > 0);
-       b64_data = rspamd_encode_base64 (pubdata, publen, -1, NULL);
-       rspamd_printf ("%s._domainkey IN TXT ( \"v=DKIM1; k=rsa; \"\n"
-                       "\t\"p=%s\" ) ;\n",
-                       selector ? selector : "selector",
-                       b64_data);
+       b64_data = rspamd_encode_base64 (pubdata, publen, -1, &b64_len);
+
+       if (b64_len < 255 - 2) {
+               rspamd_printf ("%s._domainkey IN TXT ( \"v=DKIM1; k=rsa; \"\n"
+                                               "\t\"p=%s\" ) ;\n",
+                               selector ? selector : "selector",
+                               b64_data);
+       }
+       else {
+               guint i;
+               gint step = 253, remain = b64_len;
+
+               rspamd_printf ("%s._domainkey IN TXT ( \"v=DKIM1; k=rsa; \"\n",
+                               selector ? selector : "selector");
+
+               for (i = 0; i < b64_len; i += step, remain -= step) {
+                       if (i == 0) {
+                               rspamd_printf ("\t\"p=%*s\"\n", MIN(step, remain), &b64_data[i]);
+                       }
+                       else {
+                               step = 255;
+                               rspamd_printf ("\t\"%*s\"\n", MIN(step, remain), &b64_data[i]);
+                       }
+               }
+
+               rspamd_printf (") ; \n");
+       }
 
        g_free (b64_data);
        BIO_free (pubout);