From: Vsevolod Stakhov Date: Sat, 17 Jun 2017 14:08:15 +0000 (+0100) Subject: [Feature] Split long DKIM public keys X-Git-Tag: 1.6.2~103 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fa035f5d6dfd643b6629988a3e8138ec7c6b3ec4;p=rspamd.git [Feature] Split long DKIM public keys Issue: #1676 --- diff --git a/src/rspamadm/dkim_keygen.c b/src/rspamadm/dkim_keygen.c index 42922ed35..14a2e18f2 100644 --- a/src/rspamadm/dkim_keygen.c +++ b/src/rspamadm/dkim_keygen.c @@ -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);